<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dogadd2</title>
<script> function Dog(name, breed, weight){
this.name = name;
this.breed = breed;
this.weight = weight;
} Dog.prototype.species = "Canine";
Dog.prototype.bark = function(){
if (this.weight > 25){
console.log(this.name + " Woof");
}
}; var fido = new Dog("fido", "mixed", 38);
fido.bark(); Dog.prototype.sitting = false;
Dog.prototype.sit = function(){
if (this.sitting){
console.log(this.name + " is already sitting");
} else {
this.sitting = true;
console.log(this.name + " is start sitting");
}
};
//hasOwnProperty,如果属性是在实例中定义的返回true,如果是在圆型定义返回false var barnaby = new Dog("Barnaby", "Basset Hound", 55);
console.log(barnaby.hasOwnProperty("sitting"));
barnaby.sit();
console.log(barnaby.hasOwnProperty("sitting")); console.log(fido.hasOwnProperty("sitting"));
fido.sit();
console.log(fido.hasOwnProperty("sitting")); </script>
</head>
<body> </body>
</html>

js中的hasOwnProperty的更多相关文章

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

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

  2. js中的hasOwnProperty和isPrototypeOf方法

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

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

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

  4. JS中isPrototypeOf 和hasOwnProperty 的区别 ------- js使用in和hasOwnProperty获取对象属性的区别

    JS中isPrototypeOf 和hasOwnProperty 的区别 1.isPrototypeOf isPrototypeOf是用来判断指定对象object1是否存在于另一个对象object2的 ...

  5. 浅解析js中的对象

    浅解析js中的对象 原文网址:http://www.cnblogs.com/foodoir/p/5971686.html,转载请注明出处. 前面的话: 说到对象,我首先想到的是每到过年过节见长辈的时候 ...

  6. js中两个对象的比较

    代码取自于underscore.js 1.8.3的isEqual函数. 做了一些小小的修改,主要是Function的比较修改. 自己也加了一些代码解读. <!DOCTYPE html> & ...

  7. 小结JS中的OOP(下)

    关于JS中OOP的具体实现,许多大神级的JS专家都给出了自己的方案. 一:Douglas Crockford 1.1 Douglas Crockford实现的类继承 /** * 原文地址:http:/ ...

  8. 小结JS中的OOP(中)

    此篇文章主要是提炼<JavaScript高级程序设计>中第六章的一些内容. 一:JS中OOP相关的概念 开始之前先总结JS中OOP相关的一些概念: 构造函数:JS中的构造函数就是普通的函数 ...

  9. 谈谈js中for in 需要注意的地方

    js中for in 可以遍历对象或数组的显性属性,也就是说我们自己定义的属性是可以遍历的,那些原型上默认已有的属性,例如:Object.prototype.toString.Object.protot ...

随机推荐

  1. 关于ADO.Net SqlConnection的性能优化

    Connections Database connections are an expensive and limited resource. Your approach to connection ...

  2. .NET:Threading and Exceptions

    Do handle exceptions in threads. Unhandled exceptions in threads, even background threads, generally ...

  3. Linux ./configure --prefix命令

    源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make install),具体的安装方法一般作者都会给出文档,这里主要讨论配置(configure).Configu ...

  4. ConcurrentHashMap 的实现原理

    概述 我们在之前的博文中了解到关于 HashMap 和 Hashtable 这两种集合.其中 HashMap 是非线程安全的,当我们只有一个线程在使用 HashMap 的时候,自然不会有问题,但如果涉 ...

  5. test.cpp:(.text+0xc0): undefined reference to `cv::imread(std::string const&, int)'

    opencv报错: test.cpp:(.text+0xc0): undefined reference to `cv::imread(std::string const&, int)' te ...

  6. javascript数据类型的判断

    最近看到了很多关于数据类型判断的方法,总结了下 一.javascript的数据类型 js数据分为两种类型:原始数据类型和引用数据类型.原始数据类型有:string.number.boolean.und ...

  7. 《Unix&Linux大学教程》学习笔记七:进程与作业控制

    1:进程:一个内存中的程序+程序所需数据+管理程序的各种状态信息. 2:进程由内核进行管理,内核使用调度器,给予进程一个时间片来运行,然后切换到下一个进程. 3:进程分叉 fork :创建一个子进程 ...

  8. dyld`__abort_with_payload:

    dyld`__abort_with_payload: 0x1030422f0 <+0>:  mov    x16, #0x209 0x1030422f4 <+4>:  svc  ...

  9. linux命令(53):useradd,区别于adduser

    adduser和useradd的区别: useradd是一个linux命令,但是它提供了很多参数在用户使用的时候根据自己的需要进行设置: 而adduser是一个perl 脚本,在使用的时候会 出现类似 ...

  10. Asp.Net WebApi swagger使用教程

    swagger简介 别名:丝袜哥 功能:用于生产api文档 swagger安装 Nuget搜索swagger,然后安装Swashbuckle swagger使用 生成api的xml文档 webapi项 ...