4 ms·
I would love to see class syntax in JS. Until then, this is the system I use: var MyClass = classdef(SuperClass, MixIn, AnotherMixIn, { constructor: func
by ender7 14y ago
I would love to see class syntax in JS. Until then, this is the system I use:
var MyClass = classdef(SuperClass, MixIn, AnotherMixIn, {
constructor: function() {
...
},
publicFunc: function() {
...
},
_privateFunc: function() {
...
}
});
Where the 'classdef' function takes an optional superclass, an optional set of mixins (their properties will be copied to the class's prototype), and an object defining the class. The function itself is fairly easy to write, and allows you to define classes quickly, without having to retype MyClass.prototype.blah all the time.
Some other implementations that I've seen add the ability to refer to super(), or to say MyClass.extend(...).
- MatthewPhillips 14y agoWe've all been writing a hundred varieties of this same thing for years which is why Alex is championing this "one correct way" so we can all move on to arguing about something else.