prototype & constructor

Examples: Displaying the constructor of an object

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

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

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

This example displays the following output:

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

 

All objects inherit a constructor property from their prototype.

posted @ 2016-04-12 13:58  kakaguo  阅读(127)  评论(0编辑  收藏  举报