Object.prototype.clone
Lars T Hansen
lth at acm.org
Mon Oct 22 00:23:57 PDT 2007
With the proviso that the program unit proposal has still to be fully
specified and debugged, I believe the following should work:
Somewhere:
unit Beget {
internal package Beget {
Object.prototype.beget = function (o) { /* what you expect */ }
Object.prototype.propertyIsEnumerable("beget", false);
}
}
In your code:
use unit Beget "Somewhere";
In a browser, "Somewhere" would typically be a URI.
--lars
On 10/22/07, Garrett Smith <dhtmlkitchen at gmail.com> wrote:
> On 10/21/07, Kris Zyp <kriszyp at xucia.com> wrote:
> > >> http://javascript.crockford.com/prototypal.html
> > It is the act of creating a object that inherits from/delegates to the
> > provided object. Peter is suggesting sugar for one of the important
> > mechanisms in a prototypal language. I believe the "copy" semantic is used
> > in Self. "clone" is bit misleading (well, I think "copy" is too). With
> > classes, we call it "subclassing". We could call it "subobject" :). Douglas
> > calls it "begetObjet" (nice), I personally think it is very valuable
> > construct and I like what it encourages, but on the otherhand it is so
> > easy/compact to create (about 4 lines of code), and it doesn't seem to be
> > the direction ES4 is headed, so it's omission seems reasonable.
> >
> function beget(o) {
> function F() {}
> F.prototype = o;
> return new F();
> }
>
> var x = {
> items : [1,2,3]
> };
>
> var y = beget(x);
> y.items.reverse(); // reverse my y items.
>
> x.items[0]; // What is it?
>
> The point I made earlier about mutable objects addresses this very issue.
>
> It's attractive, but easily breakable.
>
> > > YAHOO.mst.app.code = (function(){
> > > // 1100+ lines...
> > >
> > I don't think this doesn't have anything to do with the topic.
> It's little off-topic. It can cause problems in real-world programming
> was the point I was trying to make. Looking at Doug's side made me
> remember that code and the (long, excruciating) time I spent, often @
> the office until 8 or 10 on a Friday. I'm getting off topic again...
>
>
> Garrett
>
> >
> >
> > Kris
> >
> >
>
>
> --
> Programming is a collaborative art.
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
>
More information about the Es4-discuss
mailing list