所以我有这两个例子,来自javascript.info:
例1:
var animal = {
eat: function() {
alert( "I'm full" )
this.full = true
}
}
var rabbit = {
jump: function() { /* something */ }
}
rabbit.__proto__ = animal
rabbit.eat()
Run Code Online (Sandbox Code Playgroud)
例2:
function Hamster() { }
Hamster.prototype = {
food: [],
found: function(something) {
this.food.push(something)
}
}
// Create two speedy and lazy hamsters, then feed the first one
speedy = new Hamster()
lazy = new Hamster()
speedy.found("apple")
speedy.found("orange")
alert(speedy.food.length) // 2
alert(lazy.food.length) // 2 (!??)
Run Code Online (Sandbox Code Playgroud)
从示例2开始:当代码到达时 …
我是JavaScript的新手.我正在阅读JavaScript的好部分.它说 :
每个函数对象也使用prototype属性创建
所以我做了这样的事情:
function test() {
}
console.log(test.prototype);
Run Code Online (Sandbox Code Playgroud)
使用Chrome的开发人员工具,我发现输出如下:

我真的很担心这个输出.为什么constructor的prototype财产又嵌套constructor?为什么这会像链条那样继续?我在哪里错过这个概念?
提前致谢.
看来这里有区别......
让我们说我们有 function MyConstructor() {}
MyConstructor [[Prototype]]是Function.prototype,而不是 MyConstructor.prototype.
在其他(非标准/"console.log-able")字样中:
MyConstructor.__ proto__ 不是 MyConstructor的MyConstructor.prototype
试试这个:
function MyConstructor() {};
(MyConstructor.__proto__ === MyConstructor.prototype); //false?! why?
Run Code Online (Sandbox Code Playgroud)
为什么会这样?有人能解释一下这个区别吗?