问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/13494207/expected-identifier-instead-saw-new-a-reserved-word