当前位置:网站首页>JS中如何判断一个属性是属于实例对象还是继承于构造函数
JS中如何判断一个属性是属于实例对象还是继承于构造函数
2022-07-27 05:03:00 【weixin_46051260】
Object方法可借鉴链接https://www.jianshu.com/p/7fb0566322cf
通过hasOwnProperty():检测一个属性是否属于自身对象(true),还是继承于原型链上(false)
function Person(name,age){
this.name=name
this.age=age
}
Person.prototype.sex="男"
var p=new Person('张三',18)
p.phone=12345
console.log(p);
console.log(p.hasOwnProperty('phone'));//true
console.log(p.hasOwnProperty('sex'));//false
for(let i in p){
if(p.hasOwnProperty(i)){
console.log(p[i]);
}
}
边栏推荐
- pytorch中几个难理解的方法整理--gather&squeeze&unsqueeze
- 分享力扣—189.轮转数组 的三种解法
- 创建项目 实现登录注册,生成jwt,发送验证码
- C语言中堆内存介绍和管理
- 李宏毅机器学习组队学习打卡活动day03---误差和梯度下降
- Notes series k8s orchestration MySQL container - stateful container creation process
- Li Hongyi machine learning team learning punch in activity day03 --- error and gradient decline
- Li Hongyi machine learning team learning punch in activity day05 --- skills of network design
- set集合
- 初识C语言——字符串+转义字符+注释
猜你喜欢
随机推荐
用户登录-以及创建、验证短信验证码
Dnsmasq Usage Summary
Rolling Division
C语言指针入门详细介绍
322 coin change of leetcode
p7 day1 初识Flask框架
下载url-loader,用limit指定图片大小后,显示不出图片
数据库迁移报错解决
李宏毅机器学习组队学习打卡活动day01---机器学习介绍
【codeforces 1695C Zero Path】DP
The receiver sets the concurrency and current limit
node 安装调试
分享一道关于#define的选择题(内含#define在预编译时的替换规则,程序环境和预处理相关知识)
mysql 取消外键关联约束
后台品牌管理功能实现
flask蓝图
项目登录注册思路
流程控制-分支
后台实现spu管理
初始C语言——关键字static的作用









