C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript handler.construct() MethodThe handler.construct() method is used to intercept the new operation. This method returns an object. Syntax
construct: function(target, argumentsList, newTarget) Parameters
Target: The target object. argumentsList: List of the constructor. newTarget: The constructor that was originally called, p above. Return value
This method returns an object. Browser Support
Example 1
var B= function(text) {
this.text = text;
};
var Button1 = new Proxy(B, {
construct: function(target, parameters) {
document.writeln('Java Script');
var button= Object.create(target.prototype);
target.apply(button, parameters);
return button;
}
});
var button = new Button1('proxy Constructor');
document.writeln(button.text);
Output: Java Script proxy Constructor Example 2
var pro = new Proxy(function()
{}, {
construct: function(objTarget, args, oldConstructor) {
return { Value : args[0] + " to anybody" }
}
})
document.write(JSON.stringify(new pro("Hello "), null, ' '))
Output: { "Value": "Hello to anybody" }
Example 3
function M(val) {
this.val = val;
}
const N = {
construct(target, args) {
document.writeln('Constructor called');
return new target(...args);
}
};
const proxy= new Proxy(M, N)
document.writeln(new proxy('Proxi').val);
Output: Constructor called Proxi
Next TopicJavaScript handler
|