expected identifier instead saw new (a reserved word)

I want to know how can i disable JSHint's checking for this type of declarations, so i can do:

obj.new = function(){
    //...
};

instead of

obj['new'] = function(){
    //...
};

thanks

Upvotes: 1

Views: 1371

Answers (1)

James Allardice
James Allardice

Reputation: 165941

You can use the es5 option, since reserved words as property names are only valid as of ES5. Put this directive at the top of the file(s) in question:

/*jshint es5: true */

However, it's worth bearing in mind that older browsers will throw errors if they encounter such syntax. If your code needs to run in older browsers (notably IE8) then you're better off sticking to the alternative syntax, or using non-reserved words as property identifiers.

Edit: I've added a bit more detail about this error to its page on jslinterrors.com.

Upvotes: 4

Related Questions