[ACCEPTED]-JavaScript error: "is not a constructor-underscore.js

Accepted answer
Score: 25

new can only be used with a Function as the 22 operand.

new {}  // Error: ({}) is not a constructor

Check the type of Users in context: it 21 is not a Function when that exception is raised.

Happy 20 coding

alert(typeof(Users)) ought to do the trick. The result 19 should be "function" to be usable 18 as a constructor. Take note of what it is 17 in the failing case, and see below for a 16 reason.

One problematic scenario (for Users = new Users) may 15 be: an object is constructed from the Function 14 Users and then the object (now not a Function/constructor) is 13 assigned back to Users so the next new Users will go kaboom! (Look 12 in both showusers and dashboard -- is that behavior really intended?)

The 11 'correct' code is likely: var users = new Users; users.blahblah(...); that is, use 10 a new local variable and do not overwrite the global Users 9 variable/property.

The reason the error is 8 only generated when "going back" to 7 "#foobar" (a Fragment Identifier) is that no new 6 page is actually loaded and thus the JavaScript 5 is not reloaded and the current (now corrupt 4 Users) is being used. kaboom!

Excerpt from Fragment Identifier:

If the targeted 3 element is located in the current document, a 2 user agent may simply focus the targeted 1 element without having to reload it ...

Score: 0

I think its Syntax Error

this happened with 3 me when I tried to return anonymous object in my function

 var FalsEextension=false;
 return new  { FalsEextension, LargeFile };// wrong Syntax 

and the 2 correct Syntax is

 return { FalsEextension, LargeFile };

and you can use it like 1 this


More Related questions