43 ms·
I think "foo.bar is undefined, not a function" might be clearer.
by Zarel 12y ago
I think "foo.bar is undefined, not a function" might be clearer.
- deleted 12y ago[deleted]
- schrijver 12y agoNot just clearer, transmits more information!
- kevan 12y agoThis would help a lot in case where you have multiple calls chained together. foo.bar().fiz().buz() What's undefined, bar, fiz, or buz? Then you have to set a breakpoint to find out. Most people I know try to avoid writing code like this, but Knockout ViewModels are a common place where this bites me.
- eyko 12y agoIf bar() or fiz() return undefined (i.e. don't return at all), then you will still get the same error as usual undefined is not an object, I reckon.
- saraid216 12y agoThe issue isn't that the functions are returning undefined. It's... foo = {} foo.bar() Or, more commonly, foo = {}; bar = 'bar'; foo[bar]();
- CmonDev 12y agoEven better: "Error, you are using JavaScript."