4

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?

9
  • 2
    Do you get both messages in the same browser? I wouldn't be surprised if it's just messages differing by browser for the same error Commented May 17, 2013 at 18:52
  • 2
    Are you using a code library? The error could be a custom error coming from there. throw new Error("expected function: function(){}") Commented May 17, 2013 at 18:54
  • 1
    For example: stackoverflow.com/questions/6697947/… - looks like the "expected" message is old IE maybe? Commented May 17, 2013 at 18:55
  • 1
    @Ian - Yup, testet, chrome gives "string is not a function", while IE gives the "expected function" error on the same code examples. Never seen an "expected function" error in chrome myself ? Commented May 17, 2013 at 18:55
  • 2
    Oops, I found it, not in jQuery, but one of our in-house libraries. I can't believe I didn't think to check there before posting. Thanks a lot for responding. Commented May 17, 2013 at 18:58

1 Answer 1

0

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(){}';
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.