<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hasOwnProperty与isPrototypeOf</title>
</head>
<body>
<script>
// hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象。不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员。
// isPrototypeOf:是用来判断要检查其原型链的对象是否存在于指定对象实例中,是则返回true,否则返回false。
function person(firstName,lastName) {
this.firstName=firstName;
this.lastName=lastName;
}
person.prototype.setName=function(){
return this.firstName+','+this.lastName
}
var jone=new person('jone','chen');
jone.age=30
console.log(jone.setName()); // ==>jone,chen
console.log(jone.hasOwnProperty('setName')) // ==>false
console.log(jone.hasOwnProperty('age')) // ==>true
console.log(jone.hasOwnProperty('firstName')) // ==>true
console.log(person.prototype.isPrototypeOf(jone)); // ==>true
console.log(person.prototype.isPrototypeOf('jone')); // ==>false
</script>
</body>
</html>

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

isPrototypeOf:是用来判断要检查其原型链的对象是否存在于指定对象实例中,是则返回true,否则返回false。

var person = function (work) {
this.work = work;
};
person.prototype.name = "jone";
person.prototype.age = 30;
person.prototype.say = function () {
console.log(this.name + ',' + this.age + ',' + this.work)
}
var jone = new person("xuesheng");
jone.say();
console.log(person.prototype.hasOwnProperty('name'));
console.log(person instanceof Object);
console.log(jone.hasOwnProperty('work'))
console.log(person.prototype.hasOwnProperty('work'))
console.log(person.prototype.isPrototypeOf(jone))

hasOwnProperty与isPrototypeOf的更多相关文章

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

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

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

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

  3. js中的hasOwnProperty和isPrototypeOf方法

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

  4. javascript中的hasOwnProperty和isPrototypeOf

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

  5. 深入解析hasOwnProperty与isPrototypeOf

    这里采用一个实例来说明: function Person(name) { //以下都是Person的OwnProperty this.name = name; this.showMe = functi ...

  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. 三国塔防游戏android源码

    三国塔防游戏源码,这个游戏源码比较完整的,因为上传有20M限制,把代码工程包分开了,主文件是TFGame,其他res大家按照安卓包加进去就行,欢迎下载并交流 ,大家可以参考一下吧.<ignore ...

  2. jquery图片轮播,单张图片轮播时间不同

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. Case When Exists SQL

    The Case-When-Exists expression in Oracle is really handy. Here's an example of how to use it in a s ...

  4. JS限定手机版中图片大小随分辨率自动调整

    <script type="text/javascript"> var ObjImg = jQuery(".Dy_Content img"); fo ...

  5. jquery Ajax中的dataType简析

    jquery中的ajax有好几种运用方式,但是基本上都是使用的$.ajax()方法,很多人经常会使用它来从后台获取json格式的数据,但是经常发现返回的json字符串并不能自动的转换成js里的json ...

  6. excel上传和下载

    需要注意的地方: 1.js构造表单并提交 2.js中文传参encodeURI(encodeURI("中文")),action接收并转换value = URLDecoder.deco ...

  7. 生产WCF客户端类文件的命令格式

    生产WCF客户端类文件的命令格式: svcutil.exe net.tcp://127.0.0.1:8732/ChromaMI.Remote.ConfigService/RemoteConfigSer ...

  8. Java 第六天 Spring Annotation 和其它

    Annotation,是Java语言中的一种特殊的元数据语法,Spring支持使用annotation来进行对象实例化和装配 使用Annotation在Spring的配置xml中添加context命名 ...

  9. 第一章 管理程序流(In .net4.5) 之 实现多线程和异步处理

    1. 概述 本章主要讲解.net4.5如何实现多线程和异步处理的相关内容. 2. 主要内容 2.1 理解线程 ① 使用Thread类   public static class Program   { ...

  10. 1.css的语法标准

    css(Cascading Style Sheets),中文名称为层叠样式表,主要用于对html的样式设置. 在使用CSS的时候,要注意其优先级情况,优先级由下所示(数字越高,优先级越高): 浏览器缺 ...