7
cursee
7y

JSrant

Is there no other uglier way to create a constructor in JavaScript apart from using parameters for the properties?

Some of my entity has like a dozen properties (+_+)

Comments
  • 0
    well i guess encapsulation would be too high of a concept for js devs :^)
  • 1
    What? ES6 has the class keyword, use that. It's just a sugarcoat on the old thing but it makes code much easier to read.

    Also you can take the functional approach and use closures. That way you basically have infinite freedom to do whatever the fuck you want 😄
  • 3
    @Froot I definitely must commit and learn ES6 =_=
  • 2
    @Froot BTW I found Mozilla dev docs quite easy and clear to follow. Any other recommendations for ES6 documentation and references?
  • 2
    You could group those parameters in a "options" object.
    Also, if your class has so many properties maybe you should split it up.

    As for ES6, codeschool had a nice course but I don't know if it's free. And don't forget to setup Babel in your project.
  • 1
    @shellbug haven't tried Babel yet since Laravel Mix is quite easy to use.
  • 2
    @mrlinnth I don't know what that does, but if it transpiles ES6 just stick with it.
  • 2
    @mrlinnth MDN is good
  • 1
    @mrlinnth isn’t Laravel for PHP only? With Babel you can transpile ES6 to ES5 to not run into any comparability problems in any browser.
  • 3
    @zshh yes, it is php framework but since few versions ago, they included necessary tools to install and transpile JS frameworks. Because many people use laravel as RESTful api backend with JS frameworks of their choice at the front. But then again, Laravel Mix will not have full features compared to Babel for sure.
  • 2
  • 2
    @Gatgeagent ROFL nice found, as devs we are amazing 😁😁😁
Add Comment