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

前端 未结 6 2059
忘了有多久
忘了有多久 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:54

    From jQuery fasterTrim source code:

     * Usage: 
     * 
     * $(element).fasterTrim(options);  // returns jQuery object
     * $.fasterTrim.trim(" string ", options);  // returns trimmed string
    

    To answer the question, "Do not use new for side effects" means:

    Do not use new for what the constructor will do to its parameters but to create an object, side effects in constructors are baaaad!

提交回复
热议问题