On 10/21/07, Peter Michaux <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Is there a plan for a "clone" function in ES4?
>
> Object.prototype.clone = function() {
>         function F() {}
>         F.prototype = o;
>         return new F();
> };
>
> The earliest reference I have found to this function is a post by
> Lasse Reichstein Nielsen in 2003 on comp.lang.javascript
>
> http://groups.google.com/group/comp.lang.javascript/msg/5d06e72e55d5bf11
>
> In the past year this function has been evangelized by Douglas Crockford.
>
I had the misfortune of working on code that uses this pattern while
at Yahoo. Since Yahoo pretty much shuns testing and my boss didn't
really like me refactoring code, my debugging skills improved. What
mess of code. I still remember the code object. 1100+ line module
pattern

YAHOO.mst.app.code = (function(){
// 1100+ lines...

return {

};
})_

The guys would sometimes get confused and reassign the namespace to a
variable, too.
YAHOO.namespace("mst.app.code");
YAHOO.mst.app.code.getGlobal = function(k){};

YAHOO.mst.app.code = (function(){ // uh-oh, what happened to getGlobal?

});

An interesting device, hard to debug, confuses less-skilled
programmers, usually relies on too much anon functions/constructors.
Increases scope chain.

> http://javascript.crockford.com/prototypal.html
>
I don't see the part about clone. Cloning brings up the issue of "how deep".

> Given the idea has persisted for at least a four year period as
> something useful in a prototype-based language, would a clone function
> be a good addition to the language itself?
>
A Clonable interface would be an OK addition. But cloning is tricky
when it comes to mutable objects

a = {
   items : [1,2,3]
};

b = clone( a );
b.items.reverse();
a.items[0]; // 1 or 3?

How deep should clone go?

> Peter
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
>


-- 
Programming is a collaborative art.
_______________________________________________
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss

Reply via email to