15,标准对象
15.1,typeof
我们可以通过typeof获得对象的类型
typeof 123; // 'number'
typeof NaN; // 'number'
typeof 'str'; // 'string'
typeof true; // 'boolean'
typeof undefined; // 'undefined'
typeof Math.abs; // 'function'
typeof null; // 'object'
typeof []; // 'object'
typeof {}; // 'object'
这里感叹一句:一切皆对象
15.2,包装类型
和java类似的包装类型,这里举个栗子:
typeof('asd');
"string"
typeof(new String('asd'));
"object"
正常字符串是String类型,而利用包装类型产生的字符串却是object类型!!!(这就以为着,他们过不了三重等号的考验!!!!)
15.3,Date类
常用的类,具体实现比较简单,这里需要注意一个细节
时间戳的使用
if (Date.now) {
console.log(Date.now()); // 老版本IE没有now()方法
} else {
console.log(new Date().getTime());
}