js 判断存在于原型中的属性
来源:互联网 发布:php 开源网盘 编辑:程序博客网 时间:2024/05/17 01:53
<!DOCTYPE html><html><head> <title></title></head><script> function Person() { } Person.prototype.name="Nicholas"; Person.prototype.age=29; Person.prototype.sayName=function(){ alert(this.name); } var person1=new Person(); person1.name="Greg"; var person2=new Person();console.log(person1.hasOwnProperty("name"));//trueconsole.log(person2.hasOwnProperty("name"));//falseconsole.log("name" in person1);//trueconsole.log("name" in person2);//truefor (var prop in person1) { console.log(prop);//name age sayName}function hasPrototypeProperty(object,pro) {//如此可判断存在于原型中的属性 return (!object.hasOwnProperty(pro))&&(pro in object);}console.log(hasPrototypeProperty(person1,"name"));//falseconsole.log(hasPrototypeProperty(person2,"name"));//true</script><body></body></html>
0 0
- js 判断存在于原型中的属性
- js属性具体存在位置(实例/原型)
- js 判断字符 是否存在于某个字符串中
- javascript判断元素存在和判断元素存在于实时的dom中的方法
- JQuery js如何判断标签指定属性是否存在
- js----prototype原型属性
- js判断文件存在
- js判断某值是否存在于某一array数组中
- js判断页面中的某个函数是否存在
- [JavaScript]判断JS中的函数(方法)是否存在
- js判断数组或对象中的key是否存在
- Sybase 判断对象是否存在于数据库中的两种方式
- iOS数组中的判断某元素是否存在于数组中
- 判断数据库中的“存在”
- 判断某列是否存在于某表中
- 判断function是否存在于上下文
- 判断值是否存在于数组中
- 【python】判断key是否存在于dict
- 函数重载、初始化列表、复合类、析构函数
- 日出
- 解决ImportError:cannot import name xmlrpc_client问题
- springMVC:HandlerInterceptor拦截器的使用
- PAT乙级练习题B1004.成绩排名
- js 判断存在于原型中的属性
- NSOprationQueue 与 GCD 的区别与选用
- 141. Linked List Cycle 注意边界条件
- paint().paintComponent()方法的区别
- 【leetcode】202. Happy Number
- 面向对象思想(一)
- cocos2dx 一张图片的闪烁的动画
- [简明] 申请证书
- 【JZOJ 4388】 染色