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
相关推荐
Python私教4 分钟前
Python 3.15 来了:free-threading 稳定 ABI 能给高并发服务带来什么CAD老兵1 小时前
在浏览器里对比 DWG/DXF 图纸 —— @mlightcad/cad-diff-viewerLogintern091 小时前
[Matlab] 遗传算法求解TSP入门WL_arm2 小时前
Vibe Coding(氛围编程)入门艾醒(AiXing-w)2 小时前
LangChain 1.0 入门(二):LangChain 全模型标准化接入最佳实践(小白参数详解版)练习时长两年半的RL练习生2 小时前
与AI对话后对 Actor-Critic 中 TD Target 的 a‘ 来源总结十五年专注C++开发2 小时前
100w条数据丝滑滚动!Qt Model/View 架构实战(二)萧瑟余晖3 小时前
Java深入解析篇三十九之集成测试skr爱码士3 小时前
06_Qt 常用数据类型与容器:QString、QList、QVector、QMap 的性能与实现分析总有刁民想爱朕ha3 小时前
零基础Python开发「图片批量转MP4视频」工具,本地离线、免费无水印