Posts

Showing posts with the label isFunction

isFunction hacked, isCallable solution

After this post , and after some twit exchange with @ kangax , and finally after my hack for my function itself, here I am with my definitive solution to know if a passed argument could be called. var isCallable = (function(toString){ // The Latest WebReflection Proposal // Recently Updated with "explicit" cast // thanks to abozhilov for the test case var s = toString.call(toString), u = typeof u; return typeof this.alert === "object" ? function(f){ return s === toString.call(f) || (!!f && typeof f.toString == u && typeof f.valueOf == u && /^\s*\bfunction\b/.test("" + f)); }: function(f){ return s === toString.call(f); } ; })(Object.prototype.toString); 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 li...

isFunction or isIENativeFunction ?

One truly common task in JavaScript is to determinate if a specific " reference " is a Function, as we know them, or not. For those guys whose think typeof , instanceof , or Object.prototype.toString are enough, here I am with the proof things are NOT that simple, and these things are really important, business speaking, since these checks are in the core of whatever library we create or use for our Web 2.0 Application, Enterprise or not. Different Behavior Problem: Internet Explorer As historical black sheep in the browser panorama for its non standard JavaScript implementation , even for a simple task like the right manifestation of a property or function in core level, Internet Explorer, whatever version, will return false in every case described below: // alert is a function, that is why I use // this function to demonstrate // that for IE alert is not a function // sounds fun? alert(typeof alert); // object alert(alert instanceof Function); // false alert(Object.protot...