在看一篇js的论文时,看见这么一段话:
When reading property p of object x using the expression x.p, the object x is searched first for a property named p. If there is one, its value is returned; if not, x’s prototype (let’s call it y) is searched for a property named p. If there isn’t one, y’s prototype is searched next and so on. If no property at all is found, the result is the value undefined.
于是,我用下面的代码测试了下:
js 代码
- var a=function() {} ;
- a.prototype=function() {} ;
- a.prototype.prototype.test='a';
- var b=new a();
- alert(b.test);
不知道是我理解错了那段话,还是这段话是错的,希望有人来给我指点迷津,谢谢!