Immist mode with JavaScript

xiaoxiao2021-03-30  219

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];

}