lib/tools/closure.js
function Closure (parent, listOfKeys, accessor) {
  "use strict";

  var closure = {};

  listOfKeys = listOfKeys || [];
  accessor   = accessor || function () {};
  
  parent && parent.__mixin__ && parent.__mixin__(closure);

  listOfKeys.forEach(function (key) {
    closure[key] = accessor.bind(null, key);
  });

  this.getValues = function () {
    var values = {};
    Object.keys(closure).forEach(function (key) {
      values[key] = closure[key]();
      if (values[key] === undefined) {
        values[key] = null;
      }
      if (typeof values[key] === 'function') {
        throw new Error('a closure variable must be serializable, so you cannot use a function');
      }
    });
    return values;
  }

  this.setValues = function (values) {
    Object.keys(values).forEach(function (key) {
      closure[key](values[key]);
    });
  }

  this.__mixin__ = function (object) {
    Object.keys(closure).forEach(function (key) {
      object[key] = closure[key];
    });
  }

}
function Closure (parent, listOfKeys, accessor) {
  "use strict";

  var closure = {};

  listOfKeys = listOfKeys || [];
  accessor   = accessor || function () {};
  
  parent && parent.__mixin__ && parent.__mixin__(closure);

  listOfKeys.forEach(function (key) {
    closure[key] = accessor.bind(null, key);
  });

  this.getValues = function () {
    var values = {};
    Object.keys(closure).forEach(function (key) {
      values[key] = closure[key]();
      if (values[key] === undefined) {
        values[key] = null;
      }
      if (typeof values[key] === 'function') {
        throw new Error('a closure variable must be serializable, so you cannot use a function');
      }
    });
    return values;
  }

  this.setValues = function (values) {
    Object.keys(values).forEach(function (key) {
      closure[key](values[key]);
    });
  }

  this.__mixin__ = function (object) {
    Object.keys(closure).forEach(function (key) {
      object[key] = closure[key];
    });
  }

}
function Closure ( parent , listOfKeys , accessor ) { "use strict" ; var closure = { } ; listOfKeys = listOfKeys || [ ] ; accessor = accessor || function ( ) { } ; parent && parent . __mixin__ && parent . __mixin__ ( closure ) ; listOfKeys . forEach ( function ( key ) { closure [ key ] = accessor . bind ( null , key ) ; } ) ; this . getValues = function ( ) { var values = { } ; Object . keys ( closure ) . forEach ( function ( key ) { values [ key ] = closure [ key ] ( ) ; if ( values [ key ] === undefined ) { values [ key ] = null ; } if ( typeof values [ key ] === 'function' ) { throw new Error ( 'a closure variable must be serializable, so you cannot use a function' ) ; } } ) ; return values ; } this . setValues = function ( values ) { Object . keys ( values ) . forEach ( function ( key ) { closure [ key ] ( values [ key ] ) ; } ) ; } this . __mixin__ = function ( object ) { Object . keys ( closure ) . forEach ( function ( key ) { object [ key ] = closure [ key ] ; } ) ; } }
Creates a new closure manager.

@param {Object} parent
@param {Array} listOfKeys (names)
@param {Function} accessor
Creates a new closure manager .