class sugar

Peter Michaux petermichaux at gmail.com
Sat Jun 4 15:00:16 PDT 2011


On Sat, Jun 4, 2011 at 9:52 AM, Juan Ignacio Dopazo
<dopazo.juan at gmail.com> wrote:
> 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).

Yes but this is a limitation of our tools. If Firebug let you into a
closure and edit the code inside the closure, for example, you could
have this ability with the closure based system.


> 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.

Yes that is true. The prototype/new/this business really does scream
out for syntactic help. I just think the whole system could be left
behind.


> 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?

Both are efficient enough for most situations where a scripting
language can be used and as Mark mentioned the closure-based system
could be optimized more if there was motivation.

Peter


More information about the es-discuss mailing list