Global.Object.prototype.clone (clone, recursive)
copy the properties of an object into a new object

  • Parameter Object:
    the source object
  • Parameter Object:
    the (optional) target object
  • Returns
    Object the resulting object
Sourcecode in /home/hannes/helma/modules/core/Object.js:
25:   Object.prototype.clone = function(clone, recursive) {
26:      if (!clone)
27:         clone = new this.constructor();
28:      var value;
29:      for (var propName in this) {
30:         value = this[propName];
31:         if (recursive && (value.constructor == HopObject || value.constructor == Object)) {
32:            clone[propName] = value.clone(new value.constructor(), recursive);
33:         } else {
34:           clone[propName] = value;
35:        }
36:     }
37:     return clone;
38:  }