深入解析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是用来判断要检查 ...
随机推荐
- xhtml知识及head部分名词解
W3C: World Wide Web Con??? DTD: Document Type Defination DOCTYPE:Document Type meta:????? http-equiv ...
- NOIP2009 最优贸易
3. 最优贸易 (trade.pas/c/cpp) [问题描述] C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个城市之间 多只有一条道路直接相连.这 m 条道 ...
- android界面优化笔记(TODO)
1.避免使用线性布局的层层嵌套,要使用相对而已.使用线性布局越多,嵌套越多 官方文档: Optimizing Your UI
- ACCESS-如何多数据库查询(跨库查询)
测试通过:ACCESSselect * from F:\MYk.mdb.tablename说明:1.查询语句2.来原于哪(没有密码是个路径)3.查询的表名 ====================== ...
- A Tour of Go Exercise: Fibonacci closure
Let's have some fun with functions. Implement a fibonacci function that returns a function (a closur ...
- AQTime教程(1)
AQTime教程 1 简介 AQTime和MemProof都是AutomatedQA旗下的产品,AQTime比MemProof提供了更丰富强大的功能.该产品含有完整的性能和调试工具集,能够收集程序运行 ...
- 常用SQL代码段
代码使用时须测试. --聚合函数 use pubs go select avg(distinct price) --算平均数 from titles where type='business' go ...
- WinForm程序启动控制台窗口Console
本文转载:http://blog.csdn.net/oyi319/article/details/5753311 2.WinForm程序和控制台窗口Console 如果你调试过SharpDevelop ...
- 深入C语言可变参数(va_arg,va_list,va_start,va_end,_INTSIZEOF)
一.什么是可变参数 在C语言编程中有时会遇到一些参数个数可变的函数,例如printf(),scanf()函数,其函数原型为: int printf(const char* format,…),int ...
- C#实现在Winform中嵌入Word和Excel
http://www.cnblogs.com/wuzi145/archive/2012/05/08/2490680.html 在此只是介绍一个简单控件:dsoframer.ocx的使用,这个控件需要通 ...