Skip to content
soliton4 edited this page Dec 13, 2014 · 4 revisions

#class

Stability: 3 - Stable

required

simple way to create JavaScript classes.

class is a keyword.

Syntax

  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.

extends

  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

magic

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.

inherited

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.

achivement

make it easy to read your code.
if it is a class just write so.

next feature: [type safety](type safety)

Clone this wiki locally