This implementation is too simple ......... dynamic language is so good ~
Define a Command object first, the code is as follows:
Function command (obj) {
Var commandobj = obj; // save the reference of working object
Var oldprop = new object (); // Save Old Properties
// set new Properties and Save Old Properties
THIS.DO = function () {
FOR (VAR O in this) {
Oldprop [o] = commandobj [o];
CommandObj [o] = this [o];
}
}
// Restore Old Properties
THIS.undo = function () {
FOR (VAR O IN Oldprop) {
Commandobj [o] = Oldprop [O];
}
script>
DELETE OLDPROP;
Oldprop = new Object ();
}
}
If you want to call, you can write it right:
// "MC" is an Object That Has _alpha and _x attributes
VAR COM = New Command (MC);
COM._ALPHA = 20;
COM._X = 200;
com.do (); // do something ... // Remember to save this command somewhere ... // now, undo it!
com.undo ();
Simple and harmonious for this
Sighten!