JavaScript原型链测试代码

"js中__proto__和prototype的区别和关系?"

https://www.zhihu.com/question/34183746/answer/58068402

var a = {}
var b = [1,2,3]
var c = "123"
var d = function() {}
var e = new d()

console.log(a.__proto__ === Object.prototype)
console.log(b.__proto__ === Array.prototype)
console.log(c.__proto__ === String.prototype)
console.log(d.__proto__ === Function.prototype)
console.log(e.__proto__ === d.prototype)

// 只有d的prototype比较特殊
console.log(a.prototype)
console.log(b.prototype)
console.log(c.prototype)
console.log(d.prototype)

// 可以认为Object,Array,String,Function和d一样,都是构造函数
// 构造函数的__proto__都是Function.prototype
console.log(Object.__proto__ === Function.prototype)
console.log(Array.__proto__ === Function.prototype)
console.log(String.__proto__ === Function.prototype)
console.log(Function.__proto__ === Function.prototype)

console.log(Function.prototype.__proto__ === Object.prototype)

js-prototype-chain-tests.jpg