需要常记的内容

js六大数据类型:number、string、object、Boolean、null、undefined

hasOwnProperty (查询某个方法是否属于其对象);

例: var n = new Array();

Array.prototype.num2 = 1;

n.num = 1;

n.hasOwnProperty("num"); true;

n.hasOwnProperty("num2"); false; 因为不属于其直接函数,属于所有数组的共同对象Array

constructor  测试此函数是哪个函数的对象(每一个函数都会有,在创建的时候自动生成的)

例:var n = [];

console.log(n.constructor == Array); true

 Array.prototype.name = "小明";

Array.prototype.age = 1;

Array.prototype = {

name : "小明",

age : 1

}

上面两种写法是一样的,但是下面的写法会导致 constructor 指示异常,下面的写法,一般要修正指向

例如

Array.prototype = {

constructor : Array,

name : "小明",

age : 1

}

toString

 类型判断

var a = [];

Object.prototype.toString.call(a); //[Object Array]

a = null 结果是 [Object null]

a = {} 结果是  [Object Object]

 

原文地址:https://www.cnblogs.com/yuruiweb/p/5946904.html