prototype & constructor

Examples: Displaying the constructor of an objectjavascript

The following example creates a prototype, Tree, and an object of that type. The example then displays the constructor property for the object theTree.java

function Tree(name) {
  this.name = name;
}

var theTree = new Tree('Redwood');
console.log('theTree.constructor is ' + theTree.constructor);

This example displays the following output:this

theTree.constructor is function Tree(name) {
  this.name = name;
}

 

All objects inherit a constructor property from their prototype.spa

相關文章
相關標籤/搜索