参考资料:
http://www.jb51.net/article/26369.htm
http://www.cnblogs.com/jikey/archive/2010/05/05/1728337.html
http://hi.baidu.com/shirdrn/item/4a785230105ef7f0e7bb7aa6
http://www.jb51.net/article/37051.htm
关于原型的一些理解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function Person() {} function Man() {} Man.prototype = new Person(); console.log(new Man() instanceof Man); // true console.log(new Man() instanceof Person); // true console.log(new Man() instanceof Object); // true m = new Man(); p = new Person(); Man.prototype.name = "phpor"; // 则: m.name == "phpor" 但是 p.name == undefined Person.prototype.age = 17; // 则: m.age == 17 并且 p.age == 17 // 所以说,prototype和“祖宗”的概念还不太一样,虽然Man也是Person,但是Man.prototype != Person.prototype ,即: Man.prototype == Person.prototype; // false |