Minimalist Classes

Erik Arvidsson erik.arvidsson at gmail.com
Wed Nov 2 14:02:19 PDT 2011


On Wed, Nov 2, 2011 at 13:39, Mikeal Rogers <mikeal.rogers at gmail.com> wrote:
>
> var generateModelClass = function(columns) {
>
>   var definition = {};
>
>   columns.forEach(function(col) {
>     definition['get' + col] = function() {
>       return this[col];
>     };
>     definition['set' + col] = function(value) {
>       return this[col] = value;
>     };
>   });
>
>   return class definition;
>
> };
>
>
I feel like this is too strange to my liking. With something more along
what Brendan was suggesting the same could be done like this:

var generateModelClass = function(columns) {
  var c = class {},
      p = returnClass.prototype;

  columns.forEach(function(col) {
    p['get' + col] = function() {
      return this[col];
    };
    p['set' + col] = function(value) {
      return this[col] = value;
    };
  });

  return c;
};


-- 
erik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111102/47ffbd32/attachment-0001.html>


More information about the es-discuss mailing list