JavaScript原型详解

本文详细探讨了JavaScript中对象的constructor、prototype和__proto__属性,通过实例展示了这些属性之间的关系,以及它们如何帮助理解对象的继承和原型链。

在这里插入图片描述

属性释义
constructor指向对象的构造函数
prototype指向函数自身的原型对象
__proto__指向对象构造函数的原型对象
function Person(name) {
    this.name = name;
}

Person.prototype.fn = function() {
    console.log(this.name);
};

var person = new Person('小明');

person.constructor === Person; //true
person.__proto__ === Person.prototype; //true


Person.constructor === Function;  //true
Person.__proto__ === Function.prototype; //true
Person.prototype.constructor === Person; //true
Person.prototype.__proto__ === Object.prototype; //true


Object.constructor === Function; //true
Object.__proto__ === Function.prototype; //true
Object.prototype.constructor === Object; //true
Object.prototype.__proto__ === null; //true


Function.constructor === Function;  //true
Function.__proto__ === Function.prototype; //true
Function.prototype.constructor === Function; //true
Function.prototype.__proto__ === Object.prototype; //true

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值