> On 9/11/07, liorean <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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; F.prototype={constructor: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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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(){} F.prototype=o; return new F; } var a={ /* declare some properties*/ }, b=inheritFrom(a); b['prop0']='blah'; b['prop1']='blah'; /* ... */ to the following: var a={ /* declare some properties*/ }, b={ "[[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 _______________________________________________ Es4-discuss mailing list Es4-discuss@mozilla.org https://mail.mozilla.org/listinfo/es4-discuss