Javascript:
function is_object( mixed_var ){ // Finds whether a variable is an object
//
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Legaev Andrey
// + improved by: Michael White (http://crestidg.com)
if(mixed_var instanceof Array) {
return false;
} else {
return (mixed_var !== null) && (typeof( mixed_var ) == 'object');
}
}
Примеры:
is_object({foo: 'bar'});
true
|
|
|
|
А не легче ли так:
function is_object( mixed_var ){ return this instanceof Object; }Наверное всё-таки не this а mixed_var
Не прокатит, если объект передать в другой фрейм и там сделать проверку