class sugar

Juan Ignacio Dopazo dopazo.juan at gmail.com
Sat Jun 4 09:52:28 PDT 2011


Both styles are equally useful. Prototype based code has its own advantages
such as being able to easily modify the behavior of multiple objects on the
fly (very useful when working with 3rd party code for instance).

However, it is a lot easier to write concise code for the objects as
closures pattern than the prototype based one, specially considering new
toys like arrow functions.

let makePoint = (x, y) -> {
    getDistance: -> Math.sqrt(x * x, y * y)
};

We have to agree that prototype based construction is a lot more verbose and
could surely use the syntactic sugar.

Also, if you where going to standardize something that's going to be used by
developers in lots of situations that you can't predict, you would surely
chose the more efficient one (memory-wise in this case), wouldn't you?

Juan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110604/da9f2e64/attachment.html>


More information about the es-discuss mailing list