Consider this JavaScript code:
var x = new date() // "ReferenceError: date is not defined" - useful error, hints at a typo ('D'ate) var x = new MyClass.foo() // "TypeError: undefined is not a function" - bad error, no hint it might be 'F'oo
The error itself is correct, since MyClass does not have a foo method, so MyClass.foo really returns undefined , and new does not like it. The problem is that this does not mean that the user may mistakenly name the method name. Real life example:
new Meteor.collection('foo') // instead of: new Meteor.Collection('foo') // c and C look alike with many fonts at small size
Is there a portable way to detect that an object has no method before new gets the undefined passed to it automatically? __noSuchMethod__ is exactly what I'm looking for, but it looks like it's a non-standard extension. It seems that IE does not support it and V8 refused to implement it . The Chromium team also does not care about proxy server support .
There seems to be some Proxy support for Node (see this and this ) and in the form of shim ("a polyfill for the upcoming ECMAScript Reflect API, but see the mpm comments below).
Related questions (what it boils down to):
source share