图解原型及原型链

72 阅读1分钟

u=2177381769,3889804556&fm=253&fmt=auto&app=138&f=JPEG.webp

function fun () { }
 // 1. 构造函数的显式原型等于实例对象的隐式原型
        console.log('1', fun.__proto__ === Function.prototype);
        console.log(fun.prototype);

  // 2. Object.prototype.__proto__ === null Object 的原型对象是原型链尽头
        console.log('2', Object.prototype.__proto__ === null);

 // 3. 函数的显式原型指向的对象默认是空 Object 实例对象(但 Object 不满足  Function 也不满足)
        console.log(Function.prototype);
        console.log('3', Object.prototype); // 应该包含对象能调用的所有方法
 // 4. 所有函数都是 Function的实例 包括(Function)
        console.log('4', Function.__proto__ === Function.prototype);
 // 6. 对象的显式原型的构造器  指向对象本身
        console.log("6", fun.prototype.constructor === fun);