TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript handler construct() Method

JavaScript handler construct() Method with examples on javascript handler, javascript methods, javascript tutorial, apply(), construct(), defineProperty(), deleteProperty(), get(), setPrototypeOf(), set(), ownKeys(), isExtensible() etc.

<< Back to JAVASCRIPT

JavaScript handler.construct() Method

The 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

Chrome 49
Edge 12
Firefox 18
Opera 36

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);
Test it Now

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, ' '))
Test it Now

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);
Test it Now

Output:

Constructor called Proxi

Next TopicJavaScript handler




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf