On Sun, Oct 30, 2011 at 12:33 PM, Allen Wirfs-Brock
<[email protected]>wrote:
>
> On Oct 29, 2011, at 10:03 PM, John J Barton wrote:
> ...
>
>
> JS is what it is. I don't think it is possible to make prototypes
> disappear without breaking many (most??) existing JS programs.
>
(This perfectly illustrates my objection to any new features using the word
"prototype"). I assume you meant "to make |.prototype| disappear" rather
than "to make prototypical inheritance disappear". I am not suggesting
removing |.prototype|; I am suggesting that it be avoided in future work
because by now we have a lot of experience with it and its not a good thing.
>
>
> I'd love to see a riff on Gozala's selfish with the declarative
> approach. Maybe the gap is too large.
>
>
> It has been proposed in many variations.
>
> The basic way that object abstractions are instantiated in the self
> language is via a copy/initialize sequence. You send a copy message to a
> Prototype object, typically this creates a new object that inherits form
> the Prototype and then invokes the initialize method on the new object to
> set up and instance specific state.
>
> In selfish, the "new" method is the equivalent of self's "copy" method and
> selfish's "initialize" method serves a similar role to self's "initialize"
> method. If you have to define a lot of methods (typically because the
> object you are defining is going to be used as a Prototype), it's
> inconvenient to do this in the initialize method, so both self and selfish
> provide a way to directly define a new Prototype object. In self, this is
> via its IDE and reflection API. In selfish it is via the "extend" method.
>
> The "object exemplar" proposal I have talked about also exactly parallels
> this same self/selfish model. With object exemplars, the JS new operator
> corresponds to self's "copy" and selfish's "new" method. With object
> exemplars the "constructor" method corresponds to the self/selfish
> "initialize" method.
>
> So where in self you would:
> Derive a new prototype object named Dog from a prototype named Mammal
> using the IDE.
> Create a Dog instance by saying:
> Dog new: 'Labrador'
> which creates a new object that inherits from Dog. The "initialize
> method is invoked on the new instance passing "Labrador" as the argument.
>
> In selfish you would:
> Derive a new prototype named Dog by evaluating:
> var Dog = Mammal.extend ({
> initialize: function(breed) {this.breed = breed},
> /* other dog methods */
> });
> You would create a Dog instance by saying
> Dog.new("Labrador")
> which creates a new object that inherits from Dog. The "initialize"
> method is invoked on the new instance passing "Labrador" as the argument.
>
> In JS using my object exemplar proposal you would:
> Derive a new prototype named Dog by evaluating:
> var Dog = Mammal <| {
> constructor: function(breed) {this.breed = breed},
> /* other dog methods */
> });
> You would create a Dog instance by saying
> new Dog("Labrador")
> which creates a new object that inherits from Dog. The "constructor"
> method is invoked on the new instance passing "Labrador" as the argument.
>
>
> The object exemplar approach is just like self or selfish, except that it
> builds upon features that are already in JS. Specifically, it uses the new
> operator instead of a new method and it names the initialization method
> "constructor" in order to tie into the object construction mechanisms that
> already exist in JS.
>
Thanks for the excellent summary and parallel constructions. However you
missed my point. None of your examples include |.prototype|, 'dot
prototype'.
"constructor" vs "initialize" is minor, |.new| vs "operator new" is minor.
|.prototype|, with it's confusing relationship to objects and its
vocabulary distortions is not minor. Note that your examples above are all
clear and the property |.prototype| does not appear.
jjb
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss