当前位置:网站首页>Object.prototype.hasOwnProperty() 和 in
Object.prototype.hasOwnProperty() 和 in
2022-07-25 15:06:00 【深海蓝山】
hasOwnProperty() 所有继承了 Object 的对象都会继承到 hasOwnProperty 方法。这个方法可以用来检测一个对象是否含有特定的自身属性;和 in 运算符不同,该方法会忽略掉那些从原型链上继承到的属性。
in操作符:检测指定对象(右边)原型链上是否有对应的属性值。
hasOwnProperty方法:检测指定对象自身上是否有对应的属性值。
两者的区别在于in会查找原型链,而hasOwnProperty不会hasOwnProperty()语法
obj.hasOwnProperty(prop)参数:prop要检测的属性的 String 字符串形式表示的名称,或者 Symbol。
返回值:用来判断某个对象是否含有指定的属性的布尔值 Boolean。此方法不会检查对象的原型链中是否存在该属性,该属性只有是对象本身的一个成员才会返回true
示例
Object.prototype.bar = {bar:'object prototype'};
var foo = {
goo: undefined
};
console.log('bar' in foo);// expected output: true(in会查找原型链)
console.log(foo.hasOwnProperty('bar'));// expected output: false
console.log(foo.hasOwnProperty('goo'));// expected output: true
边栏推荐
- 没错,请求DNS服务器还可以使用UDP协议
- Jmeter的随机数函数怎么用
- Sudo rosdep init error ROS installation problem solution
- Handle Oracle deadlock
- Number of high-quality number pairs [bit operation characteristics + abstract ability evaluation + grouping fast statistics]
- ES5写继承的思路
- Boosting之GBDT源码分析
- 深入:微任务与宏任务
- 浏览器工作流程(简化)
- ice 100G 网卡分片报文 hash 问题
猜你喜欢

bridge-nf-call-ip6tables is an unknown key异常处理

AS查看依赖关系和排除依赖关系的办法

45padding won't open the box

Leo-sam: tightly coupled laser inertial odometer with smoothing and mapping

Live classroom system 05 background management system

006 operator introduction

树莓派入门:树莓派的初始设置

【JS高级】js之正则相关函数以及正则对象_02

39 simple version of millet sidebar exercise

Leetcode combination sum + pruning
随机推荐
When using jetty to run items, an error is reported: form too large or form too many keys
给VS2010自动设置模板,加头注释
Spark parameter adjustment and tuning
处理ORACLE死锁
MFC 线程AfxBeginThread基本用法,传多个参数
Bridge NF call ip6tables is an unknown key exception handling
Splice a field of the list set into a single string
27 classification of selectors
Install entityframework method
深入:微任务与宏任务
Content type corresponding to office file
[Nacos] what does nacosclient do during service registration
Yes, UDP protocol can also be used to request DNS server
QT connect, signal, slot and lambda comparison
万能通用智能JS表单验证
Universal smart JS form verification
Syntax summary of easygui
I hope some suggestions on SQL optimization can help you who are tortured by SQL like me
树莓派入门:树莓派的初始设置
"How to use" observer mode