Is it bad practice to not assign a new object to a variable?

前端 未结 5 705
孤街浪徒
孤街浪徒 2020-12-28 18:56

Is it bad javascript practice to not assign a newly created object to a variable if you\'re never going to access it?

For example:

for(var i=0;i

        
5条回答
  •  無奈伤痛
    2020-12-28 19:24

    It seems like your constructor is doing something else besides creating/initializing an object.

    It would be a cleaner solution to implement that extra functionality into a function or method.

    Constructors should be used to create and initialize objects.

提交回复
热议问题