What is MMClass
MMClass is just another JavaScript Class factory, like Class in Prototype, MooTools or Base2. But it follow the semantics of ES6 max-min class draft, so all codes written with MMClass are expected to be compatible with ES6.
Example
ES 6 syntax:
Class Pet { this_name = name } { console }Class Dog extends Pet { supername } { return 'Woof, woof!' } { super console }Class Cat extends Pet { return 'Meow ~~' } { super console }
ES5 version with MMClass:
var Pet = var Dog = Class { } { return 'Woof, woof!' } { $super console } var Cat = Class // if no constructor provided, // default to constructor(...args) { super(...args) } { return 'Meow ~~' } { $super console } var dog = 'Odie'dog // Output: Odie says... Woof, woof! I'm a dog, pet me! var cat = 'Garfield'cat // Output: Garfield says... Meow ~~ I'm a cat, go away!
More info about ES6 Class/ES5 MMClass
You can extend a traditional ES5 constructor function
{ this_name = name}Petprototype { console}
ES6:
...
MMClass:
var Dog = Class...
Note: As ES6, Dog.[[prototype]] should be Pet so that Dog class can inherit all "static" properties on Pet. MMClass follow this semantic via setting __proto__ . Most engines support this pseudo property, if it's not supported, MMClass will copy all properties.
You also can extend an object directly (aka. prototype-based inheritance)
var pet = { this_name = name } { console }
ES6:
...
MMClass:
var Dog = Class...
You even can extend null to avoid inheriting the properties from Object.prototype (such as isPrototypeOf/hasOwnProperty/propertyIsEnumerable)
ES6:
{}
MMClass:
var NakedObject = Class
Usage
Note: MMClass requires ES5 environment. You can try es5-shim for legacy browsers (though untested yet).
my.js
'use strict''import Class from "$PATH_TO/mmclass/src/class.js"'...
See my.js for more info
NodeJS
Installation:
npm i mmclass
Source:
var Class = Class...
AMD / CMD
Browser
TODO
- Check the recent released ES6 draft to follow the changes (the standard draft is changing dramatically...)