All examples By author By category About

stepheneb

JavaScript mixin patterns

JavaScript mixin patterns

Four different ways JavaScript variables and closures can be used to implement different mix-in patterns.

Each implementation creates a mixin that creates property getter functions for model objects.

By model object I mean a function that takes properties (keys and values)( and returns an object that:

  1. Doesn't allow direct access to the properties in the new model object.
  2. The properties are only available via getter and setter functions on the model object that mediate access.
    m1 = new Model1({ a:1, b:3, c:3 });
    a = m1.get('a'));
    => 1

source: gist.github.com/4684394

demo: bl.ocks.org/stepheneb/4684394

20130131