function Cat(){} 
 function F() {}
 F.prototype = cat ;
var f = new F()
查看 f 的 constructor 发现自动就修正为 Cat 了? 为什么呢? 是因为 new 关键字的作用吗?
谢谢大家啦!
不好意思,少一行代码:
var cat = new Cat() ;
|  |      1jarlyyn      2016-05-25 17:29:38 +08:00  1 | 
|  |      2ChiangDi      2016-05-25 17:34:25 +08:00 没有吧,运行之后 f.constructor.name 是 Function, 因为 Cat.constructor 是 Function | 
|      3SuperMild      2016-05-25 17:45:23 +08:00 via iPad 与其说修正,不如说是被污染(覆盖)了。 constructor 在 prototype 里面。 F.prototype.constructor === f.constructor | 
|  |      4daysv      2016-05-25 17:58:07 +08:00 这代码有问题吧? 小写 cat? 另外建议问这类问题之前多看看书 | 
|  |      5Sunyanzi      2016-05-25 18:01:32 +08:00 只有我觉得这毫无悬念的就是一个简单的原型链继承吗 ...  F.prototype 是小写的 cat ... 我估计 LZ 把 cat = new Cat 这行当作没用的东西给删了 ... | 
|  |      6magicdawn      2016-05-25 18:43:54 +08:00 f.hasOwnProperty('constructor') // false f.constructor === cat.constructor // true | 
|  |      8jerray      2016-05-26 11:13:01 +08:00 |