I'm looking for a way to traverse through an object and perform an action if I 开发者_C百科have an anonymous function and not perform the action if I have a native function.
This is best explained with an example:
User = {
first : String,
last : String,
email : function(email) {
// ....
}
}
User.forEach(function(prop) {
if(! native ) {
// Do something
}
});
Gut reaction is of course not, but console.log will output [Function: String]
for the String native function, and [Function]
for anonymous functions.
Thanks! Matt
You can use toString()
to look at the text of the function then look for functions without names:
/^function\s*?\(/.test(prop.toString())
精彩评论