当前位置:网站首页>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
边栏推荐
- Universal smart JS form verification
- Login of MySQL [database system]
- 45padding won't open the box
- Award winning interaction | 7.19 database upgrade plan practical Summit: industry leaders gather, why do they come?
- 27 classification of selectors
- Boosting之GBDT源码分析
- 39 简洁版小米侧边栏练习
- Install entityframework method
- Raft of distributed consistency protocol
- Gonzalez Digital Image Processing Chapter 1 Introduction
猜你喜欢

Vs2010添加wap移动窗体模板

"Ask every day" briefly talk about JMM / talk about your understanding of JMM

EDA chip design solution based on AMD epyc server

06. Neural network like

Raft of distributed consistency protocol

51 single chip microcomputer learning notes (2)

API health status self inspection

Deployment and simple use of PostgreSQL learning

ESXI6.7.0 升级到7.0U3f(2022年7月12 更新)

"How to use" decorator mode
随机推荐
27 选择器的分类
MySQL的登陆【数据库系统】
Nacos2.1.0 cluster construction
安装EntityFramework方法
IP address classification, which determines whether a network segment is a subnet supernetwork
直播课堂系统05-后台管理系统
Realsense ROS installation configuration introduction and problem solving
Unable to start web server when Nacos starts
easygui使用的语法总结
Qt connect 中, SIGNAL,SLOT 与 lambda 对比
C, c/s upgrade update
006操作符简介
dpdk 收发包问题案例:使用不匹配的收发包函数触发的不收包问题定位
L1和L2正则化
剑指Offer | 二进制中1的个数
Pl/sql creates and executes ORALCE stored procedures and returns the result set
PHP implements non blocking (concurrent) request mode through native curl
继承的实现过程及ES5和ES6实现的区别
关于RDBMS和非RDBMS【数据库系统】
LeetCode_ String_ Medium_ 151. Reverse the words in the string