3 ms·
It's about time more people starts using ES6 class constructors instead of rolling their class definition hack. This is how it's done in the calculator demo:
by thomasfl 11y ago
It's about time more people starts using ES6 class constructors instead of rolling their class definition hack. This is how it's done in the calculator demo:
CLASS({
name: 'Calc'
With babeljs you can use ES6 syntax like this:
class Calc {
}
- miralabs 11y agoCrockford talks about the bad features added to ES6, one of them class which he said is most requested by Java developers programming javascript.At the end of the talk he show way how to move out of classes/new in javascript https://www.youtube.com/watch?v=PSGEjv3Tqo0&feature=youtu.be&t=308 https://www.youtube.com/watch?v=PSGEjv3Tqo0&feature=youtu.be...
- Demiurge 11y agoCan you give a short gist of why they're bad and why should one move out of classes/new? What is the alternative?
- davej 11y agoFrom the video: function constructor(spec) { let {member} = spec, {other} = other_constructor(spec), method = function () { // accesses member, other, method, spec }; return Object.freeze({ method, other, }); }
- miralabs 11y agoits mostly because of 'this' . as per the example above, you can prevent this by doing something like that.. freeze/seal