
......
Another.prototype = new ......;
A.prototype = new Another();
B.prototype = new A();
var b = new B();
当访问bInstance的一个属性时,会先现在bInstance上查找,如果没找到,则会在bInstance.__proto__也就是aInstance上查找,如果还没找到,则会在aInstance.__proto__也就是anotherInstance上找。基于原型链查找,从而实现继承。
- 查看实例上有没有要访问的属性。
- 如果有结束查找,如果没有则在该实例的原型上查找。
- 重复第一步。
网友评论