当前位置:网站首页>How to judge whether a property belongs to an instance object or inherits from a constructor in JS
How to judge whether a property belongs to an instance object or inherits from a constructor in JS
2022-07-27 05:41:00 【weixin_ forty-six million fifty-one thousand two hundred and si】
Object Methods can learn from links https://www.jianshu.com/p/7fb0566322cf
adopt hasOwnProperty(): Detect whether a property belongs to its own object (true), Or inherit from the prototype chain (false)
function Person(name,age){
this.name=name
this.age=age
}
Person.prototype.sex=" male "
var p=new Person(' Zhang San ',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]);
}
}
边栏推荐
猜你喜欢
随机推荐
元素显示模式:块级,行内,行内块,嵌套规范,显示模式转换
[MRCTF2020]Ezpop 1
Share a multiple-choice question about variables (including global variables, local variables, the scope of variables, and life cycle knowledge points)
广(宽)度优先搜索
退出登录与jsx显示
C language string introduction and related operation functions
JS基础知识--每日学习总结①
OSI七层模型和TCP/IP四层(TCP与UDP)(笔记)
一本通1353——表达式括号匹配(栈)
node 安装调试
正则表达式
qsort — c语言中自带的排序函数(附带void*、回调函数知识点
每周学习总结
ES6中new一个箭头函数会怎样
Differences between IsNaN and number.isnan in JS
Getaverse,走向Web3的远方桥梁
背景图片相关应用-铺满,自适应
eval与assert执行一句话木马
「PHP基础知识」字符串型(string)的使用
while循环



![[极客大挑战 2019]FinalSQL 1](/img/a7/857d47639fcb38e0055a2444206b8c.png)

![[MRCTF2020]Ezpop 1](/img/c0/41873fe5864490ade403eeddc26976.png)



