-
Notifications
You must be signed in to change notification settings - Fork 2
class
#class
Stability: 3 - Stable
simple way to create JavaScript classes.
class is a keyword.
class Name {
constructor: function(constructorParameter){},
member: "default value",
"another member": undefined
};
a class simply creates a constructor for you and puts all the default members in the prototype.
class Human extends GreatApes {
};
pretty much what you expect. the GreatApes class will be the base class of Human.
constructors will be called in chain.
class Human extends GreatApes developerMixin {
};
its possible to derive from more than one BaseClass.
there is a tiny bit of
promiseland attempts to reduce the prototype chain.
instead of creating prototypes of prototypes, all prototype members of the base class will be mixed in to a new prototype.
this may inhibit monkey patching but should generally increase runtime behavior.
you can allways go back to putting together your own class if you need a prototype chain.
the inherited keyword is available to easily call the function of the base class.
class Widget extends WidgetBase {
buildRendering: function(){
var node = inherited; // calls the base function
doThings(node);
return node;
}
};
without parameters the base function is called with the same parameters as the current function.
inherited(someParameter);
you can pass parameters explicitly.
inherited expression;
the expression must be an array that contains the parameters to pass.
be aware that the parameter syntax overrides the expression syntax. a expression that is put in brackets is considered a single parameter.
make it easy to read your code.
if it is a class just write so.
next feature: [type safety](type safety)
found any errors?
missing something?
let me know