标签:
Javascript对象的值查找规则:
1 Object.prototype.foo = ‘bar‘; 2 3 function People() {} 4 People.prototype.kind = ‘People‘; 5 6 function Chinese() {} 7 Chinese.prototype = new People(); 8 Chinese.prototype.constructor = Chinese; 9 Chinese.prototype.country = ‘China‘; 10 Chinese.prototype.name = ‘Chinese‘; 11 12 var zhangsan = new Chinese(); 13 zhangsan.name = ‘zhang san‘; 14 15 console.log(zhangsan.name); // zhang san, from zhangsan object,[推测] --> Chinese.prototype中对name的设定被不会被查找 16 console.log(zhangsan.country); // China, from Chinese‘s prototype 17 console.log(zhangsan.kind); // People, from Person‘s prototype 18 console.log(zhangsan.foo); // bar, from Object‘s prototype 19 console.log(zhangsan.age); // undefine
标签:
原文地址:http://www.cnblogs.com/tala/p/4287993.html