Is there any equivalence in JavaScript to check the type of an object.
The operator typeofdoes this, but may be confused by what he reports.
For example, it typeof nullwill tell you 'object'although this is not an object (although this behavior is defined).
typeof 'a'will let you know 'string', but typeof new String('a')let you know 'object'.
typeof , ReferenceError, .
, , ( typeof ).
... ?
for ( in ).
for (var prop in obj) {
console.log(prop);
}
, /. , ...
if ( ! obj.hasOwnProperty(prop)) {
continue;
}
(, ), ...
for (var prop in obj) {
if (!obj.hasOwnProperty(prop) || Object.prototype.toString.call(obj[prop]) != '[object Function]') {
continue;
}
console.log(prop, obj[prop]);
}
jsFiddle.
multi window (.. iframe s), ...
for (var prop in obj) {
if (!obj.hasOwnProperty(prop) || ! (obj[prop] instanceof Function)) {
continue;
}
console.log(prop, obj[prop]);
}
jsFiddle.
... ...
for (var prop in obj) {
if (!obj.hasOwnProperty(prop) || obj[prop].constructor != Function) {
continue;
}
console.log(prop, obj[prop]);
}
jsFiddle.
, [[Call]] (.. ), RegExp Safaris, , invokable typeof fn == 'function'.
Ruby, Ruby class ( ) methods, Object.prototype, , , .:)
typeof JavaScript.