function Person(name,age){
this.name = name
this.age = age
}
var p = new Person('张三',11)
//创建构造函数的时候,解析器会自动为构造函数创建prototype属性,prototype属性对应的对象就是原型对象
// prototype 翻译为 原型
// prototype 用于定义构造函数创建的实例对象 所共享的属性和方法
console.log(Person.prototype === p.proto) //true
// ECMAScript 标准 是 Object.getPrototypeOf()
console.log(Person.prototype === Object.getPrototypeOf(p)) //true
console.log(Person.hasOwnProperty('name')) //true
console.log(p.hasOwnProperty('name')) //true
Person.prototype.sex = '男'
console.log(Person.hasOwnProperty('sex')) //false
console.log(Person.prototype.hasOwnProperty('sex')) //true
console.log(p.hasOwnProperty('sex')) //false
console.log(p.proto.hasOwnProperty('sex')) //true
// 原型链是一种对象之间通过原型关系关联行程的链式结构
// 原型链的查找方向
// p.proto Person.prototype Object.prototype
js 原型 和 原型链
前端喜欢研究技术2023-12-16 18:52
相关推荐
聚美智数1 分钟前
企业实际控制人查询-公司实控人查询yu859395820 分钟前
基于MATLAB的随机振动仿真与分析完整实现赵钰老师24 分钟前
【结构方程模型SEM】最新基于R语言结构方程模型分析guygg8824 分钟前
利用遗传算法解决列车优化运行问题的MATLAB实现gihigo199824 分钟前
基于MATLAB实现NSGA-III的土地利用空间优化模型vastsmile1 小时前
(R)26.04.23 hermes agent执行本地命令超级慢的原因我头发多我先学1 小时前
C++ 模板全解:从泛型编程初阶到特化、分离编译进阶YSF2017_32 小时前
C语言16-makefile(3)——makefile的模式规则星星码️2 小时前
C++选择题练习(一)herinspace2 小时前
管家婆实用贴-如何分离和附加数据库