1、hasOwnProperty判断是不是对象自身的属性,如果是继承的返回false否则true

1
2
3
4
5
6
7
8
9
function Fn(){
}
Fn.prototype.num = 10;

var obj = new Fn();
obj.id = 1;

console.log(obj.hasOwnProperty("id")); //true
console.log(obj.hasOwnProperty("num")); //false

 

2、constructor返回对象的构造函数

1
2
var obj = new Function();
console.log(obj.constructor); //function Function() { [native code] }

 

3、instanceof判断对象是否在某个构造函数上

1
2
3
4
var fn = new Function();
console.log(fn instanceof Function); //true
console.log(fn instanceof Object); //true
console.log(fn instanceof String); //false

 

4、toString把对象转换成字符串

1
2
var arr = [1,2,3];
console.log(arr.toString()); //1,2,3