Le 16/03/2012 21:26, Kevin Smith a écrit :
> Thanks, David.
>
> First, I'd like to point out that in the blog post I'm putting on the
> hat of a library author (I happen to be one, but that's beside the point).
>
> One of the first conclusions that I come to (as a library author) is
> that the idiom described here:
>
> http://wiki.ecmascript.org/doku.php?id=harmony:object_extension_literal_class_pattern
>
>
> provides a worse user experience than what I already have. The goal
> post for any class syntax or idiom is not this:
>
> function Blah()
> Blah.prototype = Object.create(BaseClass.prototype);
> Blah.prototype.a = function() {};
> Blah.prototype.b = function() {};
With new syntax, it would be:
var Blah = BaseClass <| function(){}
Blah.prototype.{
a: function(){},
b: function(){}
}
It seems we're rather close to what you describe:
> It is rather this:
>
> var MyClass = new Class({
> extends: BaseClass,
> a: function() {},
> b: function() {}
> });
>
> And in the post I conclude fairly early on that the "object extension
> literal class pattern" described above does not meet or exceed this
> goal post, not by a long shot.
>
> Now, if object literal extensions were such that I could use them in a
> "class" library (any class library), then that would be fine. But as
> indicated in the post, they cannot. The full advantages to be derived
> from object literal extensions with respect to class construction are
> *unbreakably bound* to the <| operator.
I guess what I'm failing to understand is why it's so important to have
class libraries.
I tried, in the second part of my answer, to explain what led to class
libraries. For that, I explained that they came from missing fundamental
constructs in the language for abstraction composition. I then tried to
show how new constructs help to solve the abstraction composition problem.
Assuming my demonstration was good, it seems to me that trying to have
both class libraries and using the new operators is a contradictory
idea. It's trying to solve one problem with 2 solutions. Like having 2
roofs for the same house.
I think object literal operators fail at being usable with class
libraries specifically because they are here to replace them, not work
in conjonction with them. But that's just my opinion.
So, assuing we can restart from scratch with the JavaScript, are class
libraries necessary?
If so, why? What are the operators missing?
> As such <| does not fill in missing low-level pieces of the puzzle, so
> much as dictate how higher level abstractions must be built. I cannot
> build a higher level class abstraction from fundamentals without
> leaking the implementation of that abstraction.
>
> The answer cannot be that I ought not build higher level abstractions.
I can only agree. The language is here to serve us expressing our needs.
If we are forced to limit our needs, the language should be changed...
which is what we're talking about here :-)
But what I'm trying to understand is the need for classes.
The way I see it, classes are not a solution in themselves, but rather
an approach to express encapsulation, express composition and allow code
reuse. It seems that the new operators are just a different approach
which is purely object-based with other advantages and inconvenients.
> If the answer is that we'll have a class syntax, then great. But then
> we have to ask the related question, should "super" et. all defined on
> the object literal level? And do we even need special <| or .{}
> syntax, then?
>
> Again, thanks David for reading and replying.
Thanks for your initial post.
> I have great respect for everyone's ideas, and I'm just trying to
> fully explore this one.
Likewise.
I've never really felt the need for a class library, but I'm definitely
interested in exploring if they are still needed with the new language
constructs and if so, how the language could be improved.
In my opinion, encapsulation and composition should be expressable by
the language since they are so fundamental. If a library is needed to
express something related to these concerns, it's certainly an
indication that something is missing in the language.
David
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss