function Fn() { this.name = '张泽立'; this.year = 1995; } var fn1 = new Fn(); //对于下列你可能会有疑问,可是其实下面只是一种语法糖通是过字面量来建立的底层是词法解析(早期其实解析成构造函数) var obj = { a: 10, b: 20 }; var arr = [5, 'x', true];
本地对象 | 构造函数 | 字面量 |
---|---|---|
Array | new Array() | [] |
Boolean | new Boolean() | true/false |
String | new String() | "" |
Number | new Number() | 1 |
Date |
new Date() | Date对象会自动把当前日期和时间保存为其初始值 |
RegExp |
new RegExp(p,a) | /pattern/attributes 好比:/is/g |
Math |
没有构造函数 | Math对象并不像Date, String 那样是对象的类,所以没有构造函数 |
这些都是JavaScript对象,其中Math为内置对象,一切皆对象javascript
首先我们仍是先看看javascript中一个经常使用的运算符——typeof。typeof应该算是我们的老朋友,还有谁没用过它?请看下节<<JavaScript 原型总结二 一切皆对象之typeof>>java