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

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

    You are using new to perform some action instead of to create an object and return it. JSLint considers this an invalid use of new.

    You should either use it like this:

    var x = new SomeConstructor();
    

    Or perform some action like this:

    SomeMethod();
    

    But never use new to perform an action like this:

    new SomeCosntructor(args);
    

    Doing so is considered using new for side effects because you aren't using it to create an object.

提交回复
热议问题