1.hasOwnProperty 判断是不是对象自身的属性,如果是继承的返回false否则true
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 返回对象的构造函数
var obj = new Function(); console.log(obj.constructor); //function Function() { [native code] }
3.instanceof 判断对象是否在某个构造函数上
var fn = new Function(); console.log(fn instanceof Function); //true console.log(fn instanceof Object); //true console.log(fn instanceof String); //false
4.toString 把对象转换成字符串
var arr = [1,2,3]; console.log(arr.toString()); //1,2,3