Before my last commit a clone could not contain its own properties
(only traps) and =='d the clonee. This was behaviour explicitly
specified in the original xwt reference, but its not clear what the
benefit was.
In any case a clone of an object now contains properties & does not ==
the clonee. Overcoming these two trivial limitations makes the cloning
system behave like prototype based object inheritance in standard
javascript, though with a couple of advantages:
- objects have a clean namespace. The type system and management of
the keys is done through the operators keysof & instanceof.
- traps
This example code should explain the process and potential quite well:
var sword = {
damage: 4 ,
image: "sword.png",
attack: "swing"
};
var charm = function(o){
var r = sys.clone(o);
r.damage = o.damage+2;
r.attack ++= function(){
return "sparkle,"+cascade;
};
return r;
};
var magicsword = charm(sword);
assert(magicsword!=sword);
assert(magicsword instanceof sword);
assert(6==magicsword.damage);
assert("sparkle,swing"==magicsword.attack);
assert("sword.png"==magicsword.image);
assert(4==sword.damage);
assert("swing"==sword.attack);
assert("sword.png"==sword.image);
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf_______________________________________________
Vexi-core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/vexi-core