深入解析hasOwnProperty与isPrototypeOf
这里采用一个实例来说明:
function Person(name) {
//以下都是Person的OwnProperty
this.name = name;
this.showMe = function () {
alert(this.name);
};
}
//每一个'类'都有prototype属性,而这里的protype指向的是一个prototype对象,所以这里的prototype不是OwnProperty
Person.prototype.from = function () {
alert("I come from prototype");
};
var father = new Person('js');
/*object.hasOwnProperty(proName);
判断proName的名称是不是object对象的一个属性或对象*/
alert(father.hasOwnProperty("name"));//true
alert(father.hasOwnProperty("from"));//false
alert(Person.prototype.hasOwnProperty("name"));//false
alert(Person.prototype.hasOwnProperty("from"));//true
/*object1.isPrototypeOf(object2);
对象object1是否存在于另一个对象object2的原型链中*/
alert(Person.prototype.isPrototypeOf(father));//true
//【因为Person.prototype只有constructor,from,但father里有name,showMe之外还有constructor,from】
如如图所示:Person.prototype在father的原型链中

是不是很容易就理解了呢!~_~





深入解析hasOwnProperty与isPrototypeOf的更多相关文章
- js中的hasOwnProperty()和isPrototypeOf()
js中的hasOwnProperty()和isPrototypeOf() 这两个属性都是Object.prototype所提供:Object.prototype.hasOwnProperty()和Ob ...
- hasOwnProperty与isPrototypeOf
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- typeof、instanceof、hasOwnProperty()、isPrototypeOf()
typeof 操作符 instanceof 操作符 hasOwnProperty()方法 isPrototypeOf()方法 1.typeof 用于获取变量的类型,一般只返回以下几个值:string, ...
- js中的hasOwnProperty和isPrototypeOf方法
hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员. isPrototypeO ...
- javascript中的hasOwnProperty和isPrototypeOf
hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员.isPrototypeOf ...
- hasOwnProperty和isPrototypeOf方法使用
hasOwnProperty():判断对象是否有某个特定的属性.必须用字符串指定该属性.(例如,o.hasOwnProperty("name")) //复制自w3cschool ...
- (转)js中的hasOwnProperty和isPrototypeOf方法
hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员.isPrototypeOf ...
- 理解JAVASCRIPT 中hasOwnProperty()和isPrototypeOf的作用
hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员.格式如下: 1. 示例一: ...
- javascript 中isPrototypeOf 、hasOwnProperty、constructor、prototype等用法
hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员. isPrototypeOf是用来判断要检查 ...
随机推荐
- 【暑假】[深入动态规划]UVa 10618 The Bookcase
UVa 12099 The Bookcase 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=42067 思路: ...
- Spring MVC @ModelAttribute
1.@ModelAttribute注释void返回值的方法 @Controller public class HelloModelController { @ModelAttribute public ...
- Linux PHP实现仿百度文库预览功能
1.安装openoffice: tar zxvf OOo_3.3.0_Linux_x86-64_install-rpm-wJRE_zh-CN.tar.gzcd RPEMrpm -ivh *.rpm安装 ...
- poj1741-Tree(树的分治)
题意:给一棵树,求树上长度小于等于k的链的数量. 题解:http://blog.csdn.net/yang_7_46/article/details/9966455 照着这个博客写的代码. 不到100 ...
- hdoj 1213 How Many Tables
How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 转载 SharePoint【Site Definition 系列】– 创建Content Type
转载原地址: http://www.cnblogs.com/wsdj-ITtech/archive/2012/09/01/2470274.html Sharepoint本身就是一个丰富的大容器,里面 ...
- 谷歌下设置滚动条的css样式
.oLi-lists-scroll::-webkit-scrollbar { width:5px; padding:1px; background:url(../images/repeat-bar. ...
- TCP建立连接的3次握手和关闭连接的4次挥手
#.3次握手过程状态 第一次握手:建立连接时,客户端发送SYN包(syn=j)到服务器,并进入SYN_SEND状态,等待服务器确认: 第二次握手:服务器收到SYN包,必须确认客户的SYN(ack=j+ ...
- Ant-关键元素(笔记一)
需求:使用ant脚本在控制台输出一句话 <?xml version="1.0" encoding="utf-8"?> <project nam ...
- jQuery生成二维条形码 jquery.qrcode.js
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...