expected identifier instead saw new (a reserved word)

旧街凉风 提交于 2019-12-11 11:54:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!