liorean liorean at gmail.com
Tue Sep 11 05:06:12 PDT 2007

> On 9/11/07, liorean <liorean at gmail.com> wrote:
> > It also means
> > that a prototype that is thrown away after setting up the object will
> > now be accessible.

On 11/09/2007, Lars T Hansen <lth at acm.org> wrote:
> That I don't get.  The object is the prototype object of some other
> object, the garbage collector can't collect the proto until the
> referencing object can be collected.  It's pretty clear to me that you
> can't fold the prototype into the object itself without a lot of extra
> machinery.  Perhaps you can provide a concrete example?

Not anything in production code. Conceptually:

    function F(){}
    /* add some prototype properties here */
    newObj=new F;

That way, you've protected the newObj.[[prototype]] object from being
modified by throwing it away - the only reference to it is from
newObj, and that one isn't exposed. The usefulness of doing this
instead of using scope is not obvious to me, however, it was just
another case of how to make a [[prototype]] unaccessible from the
normal language mechanics that I could think of.

> On 9/11/07, liorean <liorean at gmail.com> wrote:
> > This would get rid of the need for a function call (Crockford's object
> > function for instance) for setting up plain ES3 prototypal
> > inheritance, and would mean some structures that are not currently
> > serialisable as JSON despite being plain value structures would become
> > serialisable.

On 11/09/2007, Lars T Hansen <lth at acm.org> wrote:
> I can't argue about the serialization bit.
> I love to argue about performance, though, so I'll take your "get rid
> of the need for a function call" as an argument about performance and
> proceed from there :)

Actually, it's not performance that I was thinking of. I just prefer
the option of making the prototype relation declarative in a JSON-like
initialiser (obviously we need variable names for it to work, so it
wouldn't be *entirely* compatible with current JSON) instead of
requiring a call to a function where the only thing the function call
would be there to do is to set up a reference to a prototype object.
Not only do you need to do the call, by the way, you also need to
change from object instanciator to member assignments.

It's mostly about giving the scenario a clean looking code. Contrast
the following:

    function inheritFrom(o){
        function F(){}
        return new F;
        a={ /* declare some properties*/ },
    /* ... */

to the following:

        a={ /* declare some properties*/ },
            "[[Prototype]]": a,
            prop0: 'blah',
            prop1: 'bleh'};

I would consider being able to keep using the object instanciator when
you want to set up a relation like that a real plus when it comes to
code clarity.
David "liorean" Andersson

More information about the Es4-discuss mailing list