Re:Stop Using Constructors in JS (2012)
by couchand on Thursday November 06, 2014 @09:20AM
(#8567059)
Avoiding the use of 'new' isn't overengineering, it's idiomatic JS.
[ Parent
| on HN ]
It's dogmatic not idiomatic.
Re:Stop Using Constructors in JS (2012)
by couchand on Thursday November 06, 2014 @09:32AM
(#8567123)
JavaScript code rarely uses inheritance because it's completely out of place. Most non-trivial JS apps I've worked on make heavy use of duck-typing polymorphism. It works great because you don't need to deal with arcane class hierarchies: just make sure the object has what it needs to get its own job done.
Using a constructor in the first place in a language that really doesn't need them is what's dogmatic.
Re:Stop Using Constructors in JS (2012)
by BinaryIdiot on Thursday November 06, 2014 @12:22PM
(#8568179)
> It's dogmatic not idiomatic.
That's not accurate; there are actual, technical reasons for avoiding new hence why some advise against using it.
Re:Stop Using Constructors in JS (2012)
by phpnode on Thursday November 06, 2014 @12:50PM
(#8568444)
There are equally valid technical reasons for using `new`, so it's dogma
Re:Stop Using Constructors in JS (2012)
by BinaryIdiot on Thursday November 06, 2014 @04:01PM
(#8569740)
> There are equally valid technical reasons for using `new`, so it's dogma
I really don't want to get into this argument but that's not what dogma means. Dogma is something that comes from an authority as being undeniable but saying you can't or shouldn't use new isn't undeniable, it's deniable as you said yourself there are valid reasons for using new.
and now I hate myself. Thanks.
Re:Stop Using Constructors in JS (2012)
by phpnode on Thursday November 06, 2014 @04:11PM
(#8569799)
damn, I've been using that word slightly incorrectly for years, and now I hate myself. Thanks.
Re:Stop Using Constructors in JS (2012)
by BinaryIdiot on Thursday November 06, 2014 @10:18PM
(#8571066)
Whoa a pleasant exchange on the internet. Yay.