What side effects does the keyword 'new' have in JavaScript?

前端 未结 6 2055
忘了有多久
忘了有多久 2021-02-07 01:58

I\'m working on a plug-in for jQuery and I\'m getting this JSLint error:

Problem at line 80 character 45: Do not use \'new\' for side effects.

(new jQuery.faste         


        
6条回答
  •  别跟我提以往
    2021-02-07 02:42

    It's complaining because you're calling "new" but then throwing away the returned object, I bet. Why is that code using "new"? In other words, why isn't it just

    jQuery.fasterTrim(this, options);
    

    edit OK, well that "Starter" tool generates the code that way because it really does want a new object created, and yes it really is to take advantage of side effects. The constructor code that "Starter" generates stashes a reference to the new object on the affected element, using the jQuery "data" facility.

提交回复
热议问题