Minimalist Classes

Mikeal Rogers mikeal.rogers at gmail.com
Wed Nov 2 13:39:12 PDT 2011


To bring the comments back around a little bit to this original proposal.

One thing I can't get over with this proposal is how obvious the syntax makes the semantics. I didn't actually have to read any of the descriptions to figure out how all of this works, my mind made a set of assumptions and they turned out to be correct.

While some of the alternate proposals shave the syntax in terms of bytes they are non-obvious and I'd happily take the hit in bytes for the simplicity and lack of explanation the original proposal has.

This is on par with the destructuring proposal in terms of obviousness which I felt the previous class proposal lacked.

This also *feels* a lot like JavaScript, like the syntax was already hiding out waiting to be used, it doesn't few "new", if that makes sense.

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;

};

That is exactly what I would write if I was guessing how to generate dynamic classes.

In fact, all the examples in this proposal feel significantly more dynamic and less declarative than in http://wiki.ecmascript.org/doku.php?id=strawman:classes_as_sugar .

My 2 cents.

-Mikeal


On Oct 31, 2011, at October 31, 20117:08 PM, Axel Rauschmayer wrote:

>> Here is a proposal for minimalist JavaScript classes that enable behavior that JavaScripters today desire (as evidenced by libraries and languages galore), without adding any new semantics beyond what already exists in ES3.
>> 
>> https://gist.github.com/1329619
> 
> I like the philosophy behind it (as stated at the end of the file).
> 
> Question: If the RHS can be any expression, e.g.
> 
>      class Student objectContainingStudentProperties
> 
> Would extends work, too?
> 
>      class Student extends Human objectContainingStudentProperties
> 
> That could be a problem (grammatically) if Human could also be replaced by any expression.
> 
> What is your take on object exemplars?
> 
> Axel
> 
> -- 
> Dr. Axel Rauschmayer
> axel at rauschma.de
> 
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
> 
> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

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


More information about the es-discuss mailing list