JavaScript construct()

The Javascript handler construct() method intercepts a new operation.

Syntax:

construct: function(target, arguments, newTarget)

Parameters: target: It represents the target object. argumentsList: The list of function parameters. newTarget: It represents the constructor.


Return: Object.

Example:

<!DOCTYPE html>
<html>
<body>
<script>
var handler = function(text) {
this.text = text;
};
var print = new Proxy(handler, {
construct: function(target, parameters) {
var display= Object.create(target.prototype);
target.apply(display, parameters);
return display;
}
});
var display = new print('HELLO WORLD!');
document.writeln(display.text);
</script>
</body>
</html>
Please follow and like us:
Content Protection by DMCA.com