这里采用一个实例来说明:

 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的更多相关文章

  1. js中的hasOwnProperty()和isPrototypeOf()

    js中的hasOwnProperty()和isPrototypeOf() 这两个属性都是Object.prototype所提供:Object.prototype.hasOwnProperty()和Ob ...

  2. hasOwnProperty与isPrototypeOf

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. typeof、instanceof、hasOwnProperty()、isPrototypeOf()

    typeof 操作符 instanceof 操作符 hasOwnProperty()方法 isPrototypeOf()方法 1.typeof 用于获取变量的类型,一般只返回以下几个值:string, ...

  4. js中的hasOwnProperty和isPrototypeOf方法

    hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员. isPrototypeO ...

  5. javascript中的hasOwnProperty和isPrototypeOf

    hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员.isPrototypeOf ...

  6. hasOwnProperty和isPrototypeOf方法使用

    hasOwnProperty():判断对象是否有某个特定的属性.必须用字符串指定该属性.(例如,o.hasOwnProperty("name"))  //复制自w3cschool ...

  7. (转)js中的hasOwnProperty和isPrototypeOf方法

    hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员.isPrototypeOf ...

  8. 理解JAVASCRIPT 中hasOwnProperty()和isPrototypeOf的作用

    hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员.格式如下: 1. 示例一: ...

  9. javascript 中isPrototypeOf 、hasOwnProperty、constructor、prototype等用法

    hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员. isPrototypeOf是用来判断要检查 ...

随机推荐

  1. Mysql engine

    MySQL engine.type类型的区别:

  2. leetcode@ [263/264] Ugly Numbers & Ugly Number II

    https://leetcode.com/problems/ugly-number/ Write a program to check whether a given number is an ugl ...

  3. leetcode@ [303/304] Range Sum Query - Immutable / Range Sum Query 2D - Immutable

    https://leetcode.com/problems/range-sum-query-immutable/ class NumArray { public: vector<int> ...

  4. rpi good tutorial

    http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/quick-start/

  5. Java SAX Parser

    SAX is an abbreviation and means "Simple API for XML". A Java SAX XML parser is a stream o ...

  6. [OC Foundation框架 - 3] 指向指针的指针

    使用函数改变NSString void changeStr2(NSString **str3) { *str3 = "; } int main(int argc, const char * ...

  7. UIKit: UIResponder(转自南峰子博客)

    有问题可以加本人QQ:564702640(验证:博客园) 我们的App与用户进行交互,基本上是依赖于各种各样的事件.例如,用户点击界面上的按钮,我们需要触发一个按钮点击事件,并进行相应的处理,以给用户 ...

  8. jquery插件封装思路整理

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. NoInstall_Mysql

    安装卸载一直是mysql比较头疼的问题,前几天得知可以用绿色版的mysql,解决了这一难题.

  10. JQuery.Ajax之错误调试帮助信息介绍

    下面是Jquery中AJAX参数详细列表: timeout Number 设置请求超时时间(毫秒).此设置将覆盖全局设置. async Boolean (默认: true) 默认设置下,所有请求均为异 ...