请教一个js的prototype机制的问题

本文通过一段JavaScript代码示例,探讨了对象属性查找机制及其在原型链中的搜索过程。作者使用了一个具体的实例来验证属性是否按预期从原型链中正确获取。

在看一篇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 代码
  1. var a=function() {} ;   
  2. a.prototype=function() {} ;   
  3. a.prototype.prototype.test='a';   
  4.   
  5. var b=new a();   
  6. alert(b.test);   
但,并没有如文中所说那样,b.test还是undefined
不知道是我理解错了那段话,还是这段话是错的,希望有人来给我指点迷津,谢谢!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值