Is JavaScript's “new” keyword considered harmful?

前端 未结 12 2078
情书的邮戳
情书的邮戳 2020-11-21 23:18

In another question, a user pointed out that the new keyword was dangerous to use and proposed a solution to object creation that did not use new.

12条回答
  •  时光取名叫无心
    2020-11-21 23:32

    I agree with pez and some here.

    It seems obvious to me that "new" is self descriptive object creation, where the YUI pattern Greg Dean describes is completely obscured.

    The possibility someone could write var bar = foo; or var bar = baz(); where baz isn't an object creating method seems far more dangerous.

提交回复
热议问题