方法:
- hasOwnProperty
- isPrototypeOf
- propertyIsEnumerable
hasOwnProperty
该方法用来判断一个对象中的某一个属性是否是自己提供的( 住要用在判断属性是原型继承的还是自己提供的 )
语法: 对象.hasOwnProperty( '属性名' ) -> boolean
isPrototypeOf
凡是看到 of 翻译成 的, 反过来翻译: prototype of obj, 翻译成 obj 的 原型
因此该方法的含义是: xxx 是 xxxx 的原型
语法: 对象.isPrototypeOf( 对象 ) -> boolean
propertyIsEnumerable(了解)
这个方法用于判断对象的某一个属性是不是自己提供的( 与 hasOwnProperty 一样 ), 同时该属性要求可枚举( for-in 遍历出来)
其他
- toString
- toLocaleString
- valueOf
例: var d=new Date();
console.log(d.toString);
console.log(d.toLocalString);
Function.prototype
常用成员
- apply 和 call
- caller
- bind
apply 和 call(在函数的四种调用模式中已详细说过)
caller
了解, 一般不推荐使用. 获得函数的调用者.
概念: 调用者与被调用者
function foo1() {
foo2();
}
bind
绑定, 这个语法来源于 ES5
在获得页面元素的时候, 是否有想过将 document.getElementById 用函数存起来
var f = document.getElementById;
// f( 'id' );
f.call( document, 'id' );
instanceof 运算符
愿意: 判断某一个对象是否为某一个函数的实例. 就是判断对象是不是由指定构造方法所创建.
function Person() {}
var p = new Person();
console.log( p instanceof Person );
// p -> Person.prototype -> Object.prototype -> null
console.log( p instanceof Array );
案例:
console.log( Object instanceof Function );
console.log( Function instanceof Object );
instanceof 表示判断构造函数的原型属性是否在对象所在的原型链上.
语法: 对象 instanceof 函数 -> boolean
描述: 说 '函数.prototype' 是否在 '对象' 的原型链上