Yahoo. lang = Yahoo. Lang | {
Isarray: function (o ){
If (o ){
VaR L = Yahoo. Lang;
// If the object has the Length attribute, the splice method is also supported,
// It is considered as an array.
Return L. isnumber (O. Length) & L. isfunction (O. splice );
}
Return false;
},
Isboolean: function (o ){
Return typeof o = 'boolean ';
},
Isfunction: function (o ){
Return typeof o = 'function ';
},
Isnull: function (o ){
Return o = NULL;
},
Isnumber: function (o ){
Return typeof o = 'number' & isfinite (O );
},
Isobject: function (o ){
Return (O & (typeof o = 'object' |
Yahoo. Lang. isfunction (O) | false;
},
Isstring: function (o ){
Return typeof o = 'string ';
},
Isundefined: function (o ){
Return typeof o = 'undefined ';
},
//...
Isvalue: function (o ){
// Infinity fails
// Return (o | o = false | o = 0 | o = '');
VaR L = Yahoo. Lang;
Return (L. isobject (o) | L. isstring (o) |
L. isnumber (o) | L. isboolean (o ));
}
};...... Copy and paste the split line ......
It is reported that Yahoo. Lang. isarray was written like this before Yui 2.2.0.
Isarray: function (OBJ ){
// If safari has a bug, you have to handle the string
If (OBJ & obj. constructor &&
OBJ. constructor. tostring (). indexof ('array')>-1 ){
Return true;
} Else {
Return Yahoo. Lang. isobject (OBJ) & obj. constructor = array;
}
}, And such judgment of the array type is flawed, such as the followingCode
Function myarray (){
This. Name = 'name ';
}
VaR O2 = new myarray ();
Alert (Yahoo. util. isarray (O2); // true is displayed.
// Returns true because obj. constructor. tostring () contains the words myarray.
Function OBJ (){
This. Name = 'name ';
}
VaR o = new OBJ ();
O. constructor = array;
Alert (Yahoo. util. isarray (o); // true is displayed.
// In JavaScript, constructor is also an attribute
// Can be dynamically specified, so true is returned. Therefore, in subsequent versions of Yui, Yahoo. Lang. isarray is changed to the current format.
Isarray: function (o ){
If (o ){
VaR L = Yahoo. Lang;
// If the object has the Length attribute, the splice method is also supported,
// It is considered as an array.
Return L. isnumber (O. Length) & L. isfunction (O. splice );
}
Return false;
}, The new implementation uses another idea: if the object has the Length attribute and supports the splice method, it is considered as an array. Of course, it still has a vulnerability. We can still create an object that has the Length attribute and the splice method. However, I think the current implementation is more reasonable, because it is unlikely, and the second is to avoid the strange browser bug.
Looking at the Yahoo. Lang. isvalue introduced after Yui 2.3.0, it is actually to judge whether the parameter is a meaningful value. If the parameter is not null/undefined/nan, true is returned. (Note that this is different from the general true/false/''(Null String). These values are valid values. lang. isvalue is ideal for determining whether the value of a form field is a valid value.