Copy codeThe Code is as follows:
IsNull: function (){
Return a = null;
},
IsUndefined: function (){
Return a === undefined;
},
IsNumber: function (){
Return typeof a = 'number ';
},
IsString: function (){
Return typeof a = 'string ';
},
IsBoolean: function (){
Return typeof a = 'boolean ';
},
IsPrimitive: function (B ){
Var a = typeof B;
Return !! (B = undefined | B = null | a = 'boolean' | a = 'number' | a = 'string ');
},
IsArray: function (){
Return proto_obj.toString.call (a) = '[object Array]';
},
IsFunction: function (){
Return proto_obj.toString.call (a) = '[object Function]';
},
IsPlainObject: function (o ){
If (! O | o = win | o = doc. body ){
Return false;
}
Return 'isprototypeof 'in o & proto_obj.toString.call (o) ===' [object Object]';
},
IsWindow: function (o ){
Return o & typeof o === 'object' & 'setinterval' in o;
},
IsEmptyObject: function (o ){
For (var a in o ){
Return false;
}
Return true;
}
In the isXX series above, isUndefined is used most frequently in class libraries. Such as determining whether a parameter is passed in and whether the object has a certain attribute. But this function does not have to exist. I have removed it. The reasons are as follows:
1. isUndefined has an additional layer of function calls than full (=) or typeof. Obviously, multiple function calls are less efficient than using native operators (although insignificant), but it is obvious if isUndefined calls are called more than times. I used to add this function to my mailbox framework. It has been called more than 4000 times, and it takes nearly 1% of the time from the performance analysis tool. It is terrible to judge the call time that accounts for 1%. Of course, the isUndefined in the mailbox framework is at the top of the multi-layer closure, and access to it will take a lot of time. If this is not enough for you to give up isUndefined, please refer to the following.
2. functions are encapsulated and abstracted to some extent. It is one of the ways to organize good code and helps reduce the complexity of the Code. However, there is only one sentence in the isNull/isUndefined/isBoolean/isNumber/isString function, and the abstraction level is very low. Therefore, a function is extracted without encapsulation.
3. isUndefined (a) does not save several bytes compared to a = undefined (Oh, you can name it shorter but it loses readability ).
In summary, I removed isNull, isUndefined, isBoolean, isNumber, and isString for basic types in the class library, and directly used the typeof operator when using these judgments.