mootools/mootools-core — Issue #2318: Class incorrectly resets property
Author: GCheung55
Created: 2012-03-02 01:04:08+00:00
State: open

When a Class is created via ```new Class()```, a property that is an object is improperly reset.

https://tinker.io/6ec80/1

```javascript
var reset = function(object){
for (var key in object){
var value = object[key];
switch (typeOf(value)){
case 'object':
var F = function(){};
F.prototype = value;
object[key] = reset(new F);
break;
case 'array': object[key] = value.clone(); break;
}
}
return object;
};

var newReset = function(object){
for (var key in object){
var value = object[key];
switch (typeOf(value)){
case 'object':
var F = function(){};
F.prototype = value;
object[key] = newReset(new F);
break;
case 'array': object[key] = value.clone(); break;

//Difference right here!
default: object[key] = value;
}
}
return object;
};

var obj = {
testObj: {
'change': ['render'],
'destroy': 'destroy'
}
},
objClone = Object.clone(obj);

console.log(obj);

// destroy is missing, but it's inside __proto__
// It can't properly Object.each'd
console.log('old reset', reset(obj).testObj);

// destroy isn't missing. It's also inside __proto__
// It can be properly Object.each'd
console.log('new reset', newReset(objClone).testObj);
```