Created
December 26, 2016 06:25
-
-
Save mactive/b088ac924ec1661600a28675d89e6242 to your computer and use it in GitHub Desktop.
prototype chain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Animal(age) { | |
if (age) { this.age = age; } | |
// 这个name 不会影响 Dog 或者V, 只会影响new Animal的人 | |
this.name= "One Animal" | |
} | |
Animal.prototype.age = 1; | |
Animal.prototype.name= "One Animal"; // 优先级 P3 | |
function Dog(name) { | |
if (name) { this.name = name; } | |
} | |
Dog.prototype = Object.create(Animal.prototype); | |
Dog.prototype.constructor = Dog; | |
Dog.prototype.name = "Bubbles"; // 优先级 P2 | |
var v = new Dog('Vincent'); // Vincent 优先级 P1 | |
console.log(v.name); // Vincent | |
console.log(v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment