原型链是 JavaScript 最基本的概念,之一。想要讲明白什么是原型链也不是那么容易的事情,MDN 上有一篇关于继承和原型链的文章,把原型链解释得很清楚,可是官方文档缺少总结,看完以后可能只有一个模糊的概念,仍是不能清晰地解释出,什么是原型链。javascript
那么,简单少字的总结他来了:java
show me ur code:函数
[1]:咱们能够看看字符串对象的例子prototype
执行代码code
console.log(String); console.log(String.prototype);
能够获得相似的输出对象
ƒ String() { [native code] } String {"", constructor: ƒ, anchor: ƒ, big: ƒ, blink: ƒ, …}
[2]:继续看字符串的例子继承
let str = new String('str'); console.log(str); console.log(Object.getPrototypeOf(str)); console.log(Object.getPrototypeOf(str) === String.prototype);
能够获得相似的输出ip
String {"str"} String {"", constructor: ƒ, anchor: ƒ, big: ƒ, blink: ƒ, …} true
[3]:直接访问一下 Object
原型对象的原型原型链
console.log(Object.getPrototypeOf(Object.prototype));
null