nullObj 2015-10-17 23:24 原文
- typeof(1);
- typeof("");
- typeof([]);
- typeof({});
- typeof(null);
- typeof(undefined);
-
- [] instanceof Array;
- /\d/ instanceof RegExp;
- 1 instanceof Number;
- "xiaohong" instanceof String;
- function Point(x, y) {
- this.x = x;
- this.y = y;
- }
- var c = new Point(2,3);
- c instanceof Point;
-
- Object.prototype.toString.call(21);
- Object.prototype.toString.call([]);
- function typePrototype(obj) {
- return Object.prototype.toString.call(obj).slice(8,-1);
- }
- typePrototype("guo");
- typePrototype({});
-
-
- "guo".constructor === String;
- (1).constructor === Number;
- true.constructor === Boolean;
- ({}).constructor === Object;
- new Date().constructor === Date;
- [].constructor === Array;
-
- function People(x, y) {
- this.x = x;
- this.y = y;
- }
- var c = new People(2,3);
- c.constructor===People;
- function getConstructorName(obj){
- return obj && obj.constructor && obj.constructor.toString().match(/function\s*([^(]*)/)[1];
- }
- getConstructorName(new Date());
- getConstructorName(null);
- getConstructorName(12);
推荐阅读