hasOwnProperty方法的使用
来源:互联网 发布:厦门seo分享 编辑:程序博客网 时间:2024/06/01 10:12
javaScript中hasOwnProperty函数
返回值:布尔值,指出一个对象是否具有指定名称的属性。
使用方法:
object.hasOwnProperty(proName)
其中:
参数object是必选项。一个对象的实例。
proName是必选项。一个属性名称的字符串值。
如果 object 具有指定名称的属性,那么javaScript中hasOwnProperty函数方法返回 true;反之则返回 false。此方法无法检查该对象的原型链中是否具有该属性;该属性必须是对象本身的一个成员。
example 1:
在下例中,所有的 String 对象共享一个公用 split 方法。下面的代码将输出 false 和 true。
var s = new String("JScript");console.log(s.hasOwnProperty("split"));//output falseconsole.log(String.prototype.hasOwnProperty("split"));//output true
example 2:
var man = {hands:2,heads:1,legs:2};if(typeof Object.prototype.clone == "undefined"){ Object.prototype.clone = function(){}; // 把clone方法加到所有对象上}for(var i in man){ if(man.hasOwnProperty(i)){ console.log(i + ":" + man[i]); }}加了hahOwnProperty判断,输出的结果是:
hands:2
head:1
leg:2
example 3:
example 3:
var man = {hands:2,head:1,leg:2};if(typeof Object.prototype.clone == "undefined"){ Object.prototype.clone = function(){};// 把clone方法加到所有对象上}for(var i in man){ console.log(i + ":" + man[i]);}没有加hasOwnProperty判断,输出的结果是:
hands:2
head:1
leg:2
clone:function (){}
参考书籍:《javascript设计模式》 Stoyan Stefanov 著,陈新 译
参考书籍:《javascript设计模式》 Stoyan Stefanov 著,陈新 译
0 0
- hasOwnProperty方法的使用
- hasOwnProperty方法的使用
- hasOwnProperty方法的使用
- 在for...Loops中使用hasOwnProperty()方法
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- JavaScript中的hasOwnProperty和isPrototypeOf方法使用实例
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- js hasOwnProperty方法
- Object 对象方法 hasOwnProperty()
- hasOwnProperty方法,检索ajax响应对象的存储
- hasOwnproperty的使用,看是不是对象自身下面的属性
- 使用hasOwnProperty过滤原型链上下来的属性
- js使用in和hasOwnProperty获取对象属性的区别
- JS的hasOwnProperty
- JS的hasOwnProperty
- log4j 日志限制大小 拆分成30个 不按日期分日志 按大小拆分 按日期产生
- 快速幂取模
- bochs安装
- 一个简单的判断三角形形状的C程序
- 一个说明
- hasOwnProperty方法的使用
- android mediaRecorder详细讲解及使用
- Aptana Studio 打开报 Could not launch the product the specified workspace cannot becarated.
- Powerdesigner 连接 sqlserver2008 一些问题及解决汇总
- java JFrame去掉标题栏后如何实现鼠标移动到边框可以进行拖拉以放大缩小
- 如何防止android Toast重复显示
- OFBIZ分享:库存
- 电脑文件丢失后还能恢复吗
- 利用用户自己的服务器、tomcat下的解决iOS7.1企业应用无法安装应用程序 因为证书无效的问题