(转)js中的hasOwnProperty和isPrototypeOf方法
hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象。不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员。
isPrototypeOf是用来判断要检查其原型链的对象是否存在于指定对象实例中,是则返回true,否则返回false。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
function siteAdmin(nickName,siteName){ this .nickName=nickName; this .siteName=siteName; } siteAdmin.prototype.showAdmin = function () { alert( this .nickName+ "是" + this .siteName+ "的站长!" ) }; siteAdmin.prototype.showSite = function (siteUrl) { this .siteUrl=siteUrl; return this .siteName+ "的地址是" + this .siteUrl; }; var matou= new siteAdmin( "愚人码头" , "WEB前端开发" ); var matou2= new siteAdmin( "愚人码头" , "WEB前端开发" ); matou.age= "30" ; // matou.showAdmin(); // alert(matou.showSite("http://www.css88.com/")); alert(matou.hasOwnProperty( "nickName" )); //true alert(matou.hasOwnProperty( "age" )); //true alert(matou.hasOwnProperty( "showAdmin" )); //false alert(matou.hasOwnProperty( "siteUrl" )); //false alert(siteAdmin.prototype.hasOwnProperty( "showAdmin" )); //true alert(siteAdmin.prototype.hasOwnProperty( "siteUrl" )); //false alert(siteAdmin.prototype.isPrototypeOf(matou)) //true alert(siteAdmin.prototype.isPrototypeOf(matou2)) //true |
(转)js中的hasOwnProperty和isPrototypeOf方法的更多相关文章
- js中的hasOwnProperty和isPrototypeOf方法
hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员. isPrototypeO ...
- js中的hasOwnProperty()和isPrototypeOf()
js中的hasOwnProperty()和isPrototypeOf() 这两个属性都是Object.prototype所提供:Object.prototype.hasOwnProperty()和Ob ...
- 判断js中各种数据的类型方法之typeof与0bject.prototype.toString讲解
提醒大家,Object.prototype.toString().call(param)返回的[object class]中class首字母是大写,像JSON这种甚至都是大写,所以,大家判断的时候可以 ...
- JavaScript -- 时光流逝(五):js中的 Date 对象的方法
JavaScript -- 知识点回顾篇(五):js中的 Date 对象的方法 Date 对象: 用于处理日期和时间. 1. Date对象的方法 <script type="text/ ...
- JavaScript -- 时光流逝(三):js中的 String 对象的方法
JavaScript -- 知识点回顾篇(三):js中的 String 对象的方法 (1) anchor(): 创建 HTML 锚. <script type="text/javasc ...
- 在JS中调用CS里的方法(PageMethods)
在JS中调用CS里的方法(PageMethods) 2014年04月28日 11:18:18 被动 阅读数:2998 最近一直在看别人写好的一个项目的源代码,感觉好多东西都是之前没有接触过的.今天 ...
- Angular.js中处理页面闪烁的方法详解
Angular.js中处理页面闪烁的方法详解 前言 大家在使用{{}}绑定数据的时候,页面加载会出现满屏尽是{{xxx}}的情况.数据还没响应,但页面已经渲染了.这是因为浏览器和angularjs渲染 ...
- JS中的五种去重方法
JS中的五种去重方法 第一种方法: 第二种方法: 第三种方法: 第四种方法: 第五种方法:优化遍历数组法 思路:获取没重复的最右一值放入新数组 * 方法的实现代码相当酷炫,* 实现思路:获取没重复的 ...
- JS中的call()和apply()方法(转)
转自:http://uule.iteye.com/blog/1158829 JS中的call()和apply()方法 博客分类: JS 1.方法定义 call方法: 语法:call([thisOb ...
随机推荐
- unity 优秀开源项目
ihaiu.GUIDRef (查看项目资源使用情况) http://blog.ihaiu.com/unity-GUIDRef Ihaiu.PoolManager (对象池) http://github ...
- 03 Go 1.3 Release Notes
Go 1.3 Release Notes Introduction to Go 1.3 Changes to the supported operating systems and architect ...
- python基础--logging模块
很多程序都有记录日志的需求,并且日志中包含的信息即有正常的程序访问日志,还可能有错误.警告等信息输出,python的logging模块提供了标准的日志接口,你可以通过它存储各种格式的日志,loggin ...
- find命令的使用
在以.conf结尾的文件里面查找含有aaa字符串的那一行 ( -name后面可以写 "*.*" 即匹配所有的文件 ) find / -name "*.conf& ...
- Little C Loves 3 I
CF#511 div2 A 现场掉分赛(翻车),就是这道题被叉了...qwq 其实就是一道水题: 因为CF有spj,所以直接构建特殊情况就行了. 当 n 是3的倍数的时候,显然 1,1,(n-2) 显 ...
- MySQL基础 - 视图
创建视图: 假设要将posts表的前十条数据作为视图 mysql> CREATE VIEW view_test AS SELECT * FROM POSTS LIMIT 10; 使用: 可以把视 ...
- 【oracle】入门学习(二)
oracle登录身份有三种:normal 普通身份sysdba 系统管理员身份sysoper 系统操作员身份每种身份对应不同的权限 sysdba权限:●启动和关闭操作●更改数据库状态为打开/装载/备份 ...
- LeetCode282. Expression Add Operators
Given a string that contains only digits 0-9 and a target value, return all possibilities to add bin ...
- Emacs 启动优化二三事
Emacs 启动优化二三事 */--> div.org-src-container { font-size: 85%; font-family: monospace; } p {font-siz ...
- #JS Ajax的error函数
使用jquery的ajax方法向服务器发送请求的时候,常常需要使用到error函数进行错误信息的处理, 一般error函数返回的参数有三个: function(jqXHR jqXHR, String ...