Speed will be the same with every browser, IE will do some extra check only if passed argument is not a function.The "native" case could be a performance greedy check and we do not like eval in any case.The "isFunction" name is not appropriate, cause a function is not a Host Object, as is effectively alert, as example, in Internet Explorer.isCallable simply gets the best from old proposal, threading edge cases in a specific way for the edge browser, Internet Explorer.Enjoy!

In this case I simply used language features to obtain shortcuts and avoid static unoptimized strings removing as example "[object Function]" and "undefined" from the possible resulted gzipped/inflated/packed dictionary. The result? My code once optimized does not increase the global size cause I am always focused on reused variable or functions name and common operations ;)

mate, you can do whatever you want, I write my code here and my proposal. Nobody has definitive solution in JS, algorithms a part.

P.S. I hacked your callback, would be nice to write people whose helped you to find your solution, as I did with kangax about the name. I don't mind in any case while your link is here in my comments ... regards

I have to agree with DBJ. If shortcuts are used they should be commented for future readers (even your future self may benefit from this). Let a minifier and gzip handle the bulk of the compression, there's no point in having single letter identifiers.

If you're looking for performance, you should replace your regular expression with indexOf.

I said already, I won't reply. Every comment is in the other post, the first link in this one. If you are lazy to click next time I will update a post rather than create a new one so problem solved 'cause as I have said everything is explained there.indexOf requires a manual ("" + f) plus a variable to store it plus two compared values 0 or 1 to obtain the same result. Not sure it is faster.At the same time, the second check will be performed in IE only if the first one did not pass so it is an edge case itself and performances are 5 times better than DBJ proposal, for example. Just test it widely and you will see.Finally, f for function, s for string, u for undefined, I wonder you guys how many time waist writing absolutelyMeaningFulVariableName in3LinesOfCode ... I do not, sorry. DBJ already commented the code in any case, so if something is not clear I will clarify.

Hmm, your attitude to questions and suggestions about your code comes across really badly. You don't need to take it as a personal attack and attack back. It comes across like a teenager who's just heard an negative comment about their favourite band.

In reply to kangax, you start "obviously not", suggesting they are silly / stupid for not noticing in the first place. Now, it could be the case that kangax is stupid (I suspect not), it could be that they simply misread your code, it could be that they're proving your code isn't that obvious at all. Regardless of that, "obviously not" serves only to make you look arrogant and doesn't help anyone.

In reply to DBJ you once again resort to attacking, suggesting code unlike yours is for newbies. Once again this sounds massively arrogant, reminiscent of The Emperor's New Clothes. You then sarcastically poke fun when you find an error in his code. Is this helpful to anyone? If the intention behind your blog is to inform, help and educate others, why be so unhelpful in the comments?

Believing oneself to be infallible is not the way forward. Listen to suggestions, if you think they're wrong, explain why. When it comes to opinion, debate is healthy and should be encouraged, not beaten down with sarcasm.

Jake, it is quite obvious you completely missed the background behind this post, which was to explain to DBJ that his tentative was not good, specially after a solution was already provided by me and others before, jQuery library itself which was more reliable than first 4 version DBJ posted in its blog even if versions are more than 5, trust me.Summary here, which is the second "flame" about the problem. This is the first one.As you can spot there, DBJ even declared Mr Crockford was going to comment something currently old, threaded dunno how many times, and with more than a better solution than DBJ proposed one, which posted un-tested code which failed every time after 5 minutes.About kangax, trust me, He knows better than me that expression would have certainly produced undefined.My point is that I do not like flames that much, even if sometimes I am in pole position to create one ... but after a while I get bored and DBJ with his "not listening" way could comment with details whatever he wants even it keeps not working.Arrogance? I guess you discovered WebReflection just recently, right? Well, I hope you'll come back, if interested, to understand that I always take care about suggestions, but only if reasonable and good one. That's how I learned what I know about programming and web developing, whatever language it is.Best Regards

var declaration, as function creation, are resolved before everything else. The "left to right" I was talking about is about typeof u, where u is already defined because declared as a var in the scope, returned to u, the var itself. Your example shows declaration parsing priority, but does not explain the logic behind var u = typeof u; where left to right is the assignment. Could have been typeof u; var u; and if it was like that, DBJ woul dhave been correct about obfuscation. That is why I think there is no obfuscation at all in my code.

considering that an Object like this: { toString: undefined, valueOf: undefined }is both user created and something nobody will never use in a real case scenario, I am pretty much happy about the error results which aim is to block possible malicious objects to pass a function which aim is to make something callable for sure. In few words, aim reached, that object is not callable, which is better than a false positive, imho. If you use Function.prototype.call(HostObject) you could obtain same error in IE so I guess it is ok. Thanks in any case for that page test. Regards

abozhilov I wonder if rather than "just post" you read my code and tried it. It works with everything and I am not attaching anything. If not, please tell me a single case where my isCallable fails, thanks.

Finally, I hope you are not just yet another new webreflection discoverer ... but you are acting like one.

abozhilov, I have already fixed the function and now I tell you why my bored answer OK?

You pretended with a comment to tell me that my function is crap because "Flanagan befre ... and attached properties after"

Both replies did not make sense and I was not attaching anything indeed.

Your solution is not a solution, it is not testing the fact the object is callable, it is excluding a possible internal property from a prototype chain (double underscore as prefix/postfix is usually genuinely reserved for browsers) and it is extremely slow for both try catch usage plus zero in-closure shortcuts.

So, what we discovered today?That I simply forgot an explicit cast for weird cases (but thanks for your test case, that was sufficient to understand my function real problem) and that you had no idea why my function generated an error, but you had in any case to blame something I've never done before - attached properties - and me after, acting arrogant, pretending I am the one.

Finally, you did exactly the same error somebody did a while ago in jQuery dev list, replying without understanding the code.

You want to come back with a different approach? You'll be more than than welcome!You don't? Is not gonna be a massive lost for WebReflection if this is the way you suggest bugs or propose alternatives.

"Your solution is not a solution, it is not testing the fact the object is callable, it is excluding a possible internal property from a prototype chain (double underscore as prefix/postfix is usually genuinely reserved for browsers)"

Yes reserved for browsers. In your "solution", prototype chain is visible for all. And after this fact.Whats happen, if i override test method of RegExp???? I broke your perfect code..... Because everything in RegExp.prototype is public. What is the Regular Expression concept? Maybe for testing type of object?!?

abozhilov you cannot be serious, I am starting to think you are DBJ with a fake name.

You completely "jumped" the part where your blaming analysis was wrong, as wrong is your solution.

First error:c instanceof FunctionWith sandboxes (frames and iframes) isntanceof will always fail. You do not deeply understand the problem but you pretend to have a solution.

Second error:!!(c.__t__ = c.__t__ && false)you are assigning an obtrusive __t__ property to every object passed for your "solution" and you do not know that !!c.__t__ would have produced the same result in that expression. I call this bad code design.

Third error:You are acting in a hilarious way.Nobody said JavaScript is secure, JS beauty is its malleability indeed.If your point is that some idiot could redefine the RegExp.prototype.test method how can you propose this as fallback for your test?return !!String.prototype.indexOf.call(c, 'null');

Please stop to embarrass yourself and consider that if I write or do some mistake I am ready to learn something new ... which is the difference between me and you I guess.

First error: instanceof This is not error. In sandboxes Function is complete different object. Allright, i have question for you. Whats happen if you defined.Function.prototype.new_member; In sandbox we don't have, new_member. That say, this two object is complete different. And instanceof is best way for safe application from error in this case.

Second error: c.__t__ = c.__t__In JavaScript if object doesn't not have that property __t__. Return undefined. In my code this safetly operation. If __t__ have any value, not changes. I don't attach anything! Understand?

What about this? Tell us, why in the second case when i use isFunction, my browser throw error?And instanceof is the best way to check type of object. BB, and sometime is good idea thinking about problem. Not only copy/paste, that write Doug, Jhon or anything else...

In JavaScript if object doesn't not have that property __t__. Return undefined. In my code this safetly operation. If __t__ have any value, not changes.I don't attach anything! Understand?

which demonstrate how low is your JS level, I have nothing else to say and you neither but you do not learn.You are a good throll indeed, and I find kinda funny to publish your deliriums, so please go on, you cannot get worse than this ;-)

P.S. as rule, I always publish comments unless there is no spam and no offensive content. This is just WR netiquette. Have fun today, OK? I am going back to work now

You are yet another "copy/paste" man. I don't wasting the time, with people like you! I never told. "I know JavaScript"... But you... You are arrogant fool! BB and i hope one day, me and you meeting anywhere.

Ah ah ah, you are the most hilarious wannabe ever! Thanks to make my day :D

P.S. I may result arrogant but for sure I do not post without understanding the code before, commenting it, and proposing solutions just to appear cool and skilled. If there is something I did not consider, I ask, and eventually I learn something, I do not keep bothering without valid reasons.

nobody guarantee nothing with JS and I have never said I guarantee something.

This isCallable function simply tell you if you can call a function and after you have no idea how many other discussion about this and everywhere with whoever.

You should read the old post, the jQuery dev discussion, visit the kangax website, understand the problem, be realistic about daily JavaScript environment, and only after this investigation, you can come back and discuss about my function, otherwise we both waist our time, OK?

These are only suggestions, you can take them, you can ignore them keep talking like the last arrived JS dev wannabe, writing or confirming your mistakes and/or typos misunderstanding 9/10 of problems/features/reasons/etc,etc

When you'll start to write something meaningful and pertinent I will reply without problems while If you want to ask something specific I will be happy to reply.