Minimalist Classes

Mikeal Rogers mikeal.rogers at gmail.com
Wed Nov 2 14:20:46 PDT 2011


I guess we just don't agree then, I find this alternative very unintuitive.

On Nov 2, 2011, at November 2, 20112:02 PM, Erik Arvidsson wrote:

> 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/358e71ca/attachment-0001.html>


More information about the es-discuss mailing list