From: Scott H. <sco...@us...> - 2005-05-16 23:07:12
|
Update of /cvsroot/actionstep/actionstep/src/org/actionstep In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16348/src/org/actionstep Modified Files: NSObject.as Log Message: memberwiseClone is now perfect some comments added Index: NSObject.as =================================================================== RCS file: /cvsroot/actionstep/actionstep/src/org/actionstep/NSObject.as,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NSObject.as 10 May 2005 04:03:07 -0000 1.3 --- NSObject.as 16 May 2005 23:05:59 -0000 1.4 *************** *** 49,60 **** } public function memberwiseClone():NSObject { var res:Object = new Object(); - res.__proto__ = getClass().prototype; for (var p:String in this) { res[p] = this[p]; } return NSObject(res); } --- 49,88 ---- } + /** + * Creates a shallow copy of the object. + * + * A shallow copy of an Object is a copy of the Object only. If the Object + * contains references to other objects, the shallow copy will not create + * copies of the referred objects. It will refer to the original objects + * instead. + */ public function memberwiseClone():NSObject { var res:Object = new Object(); + // + // Object prototype chain and constructor stuff (important so that further + // calls to clone will succeed, as well as getClass() use). + // + var constructor:Function = getClass(); + res.__proto__ = constructor.prototype; + res.__constructor__ = constructor; + + // + // Copy all the properties + // for (var p:String in this) { res[p] = this[p]; } + // + // Fire the constructor + // + // NOTE: + // We are not currently storing the arguments as originally passed + // to the constructor, and this might pose a problem. In any case, it + // should be fairly easy to do if necessary. + // + constructor.apply(res, []); + return NSObject(res); } |