文章出處

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

 


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()