自定义对象实例原型对象链
<!DOCTYPE html><html lang="zh"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title></head><body><script>// 自定义构造函数function Rectangle (w, h) {this.width = w;this.height = h;this.getArea = function() {return '矩形的面积为:' + this.height * this.width;};}// 你要想知道一个对象的原型对象是谁,你只需要看这个对象是通过哪个构造函数创建的。// 例如,rect1 这个对象是通过 Rectangle 构造函数创建的,因此 rect1 的原型对象是构造函数 Rectangle 的 prototype 属性的值。var rect1 = new Rectangle(200, 400);console.log(rect1);// rect1.__proto__ --> Rectangle.prototype.__proto__ --> Object.prototype</script></body></html>
本地对象实例的原型对象链
<!DOCTYPE html><html lang="zh"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title></head><body><script>// 1. Object 对象实例的原型对象链var obj1 = {name: '李忠易'};console.log(obj1)// Object 对象实例的原型对象链是最短的// obj1.__proto__ --> Object.prototype// 2. Array 对象实例的原型对象链var arr1 = [1, 2, 3];console.log(arr1)console.dir(Array)// Array 对象实例的原型对象链// arr1.__proto__ --> Array.prototype.__proto__ --> Object.prototype</script></body></html>