While going through the angular source code (which I do occasionally), I came across an interesting 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)
}
This check is part of the angular.bind
implementation. You can see the complete snippet here.
Here's how isFunction
is implemented:
function isFunction(value) {return typeof value === 'function';}
Just to clarify:
I understand what the instanceof
operator does. It verifies if a function's prototype (for example, RegExp.prototype
) is present on the prototype chain starting from a specific object.
Now, my question is:
Can you provide me with a scenario where the above code will activate the else clause? I'm particularly curious about the second part of the expression; I know it can result in failure by not supplying a function.
The comment mentions a strange behavior in IE, but I haven't been able to replicate it.