In the current Chrome, if I do this:
var i = 'foo';
i();
I get an error 'string is not a function'. I get similar errors if i is a number, undefined, etc.
However, from some real-life, more complex code, sometimes I see a different error:
'expected function: function(){}'
I am trying to figure out exactly how these two errors differ, or, to look at it another way, how to write a minimal code snip that will trigger the 'expected function' error.
I tried fiddling with callbacks, and call/apply, but none of those trigger this. Can anyone explain how to reproduce this error?
1 Answer 1
There is no specification what error message should be. Therefore each vendor implements it's own. The only way to unify this is to verify data yourslef and throw error that you expect.
var i = 'foo';
if (!$.isFunction(i)){
throw 'expected function: function(){}';
}
throw new Error("expected function: function(){}")