美文网首页
prototype chain - javascript

prototype chain - javascript

作者: Zihowe | 来源:发表于2017-10-07 07:16 被阅读14次
image.png
function Person(firstname, lastname) {
    
    this.firstname = firstname;
    this.lastname = lastname;
    
}

Person.prototype.greet = function() {
    console.log('Hello, ' + this.firstname + ' ' + this.lastname);
};

var john = new Person('John', 'Doe');
john.greet();

var jane = new Person('Jane', 'Doe');
jane.greet();

console.log(john.__proto__);
console.log(jane.__proto__);
console.log(john.__proto__ === jane.__proto__);

相关文章

网友评论

      本文标题:prototype chain - javascript

      本文链接:https://www.haomeiwen.com/subject/womdyxtx.html