I was staring at the angular source code (as I do from time to time) and I was surprised to see the following check:
if (isFunction(fn) && !(fn instanceof RegExp)) {
} else {
// in IE, native methods are not functions so they cannot be bound (note: they don't need to be)
}
It's part of angular.bind
implementation. The full snippet can be found here.
This is the implementation for isFunction
(in case you were wondering):
function isFunction(value) {return typeof value === 'function';}
Now, let me add this, just in case:
I know what instanceof
operator does. It checks to see if a function's prototype (in this case RegExp.prototype
) can be found on the prototype chain starting from a particular object.
Now, my question is:
Can you give me an example of a scenario where the above code will follow the else clause? I'm interested in the second part of the expression, I know you can make that condition fail by not providing a function.
That comment warns me about a weird behaviour in IE, but I cannot reproduce it.