mootools/mootools-core — Issue #2312: Object access in Class broken?
Author: madrussa
Created: 2012-02-24 17:16:55+00:00
State: open

I've only tested in Google Chrome but having objects set in a class appears to implement extra prototypes which interfere with standard Object functions. For example having an object on the class with key value pairs in it, you can't use Object.getLength(this.object); or Object.keys(this.object);

Please see the example below. See that the first alert ouputs 0 when you expect it to output 3.

```javascript
var testClass = new Class({
classObject: {
'key1' : 'class value1',
'key2' : 'class value2',
'key3' : 'class value3'
},
initialize: function(obj)
{
this.argumentObject = obj || {};
this.initObject = {
'key1' : 'init value1',
'key2' : 'init value2',
'key3' : 'init value3'
};
},
test: function()
{
alert('classObject has ' + Object.getLength(this.classObject) + ' values'); // Expected 3
alert('arguementObject has ' + Object.getLength(this.argumentObject) + ' values'); // Expected n
alert('initObject has ' + Object.getLength(this.initObject) + ' values'); // Expected 3
}
});

test = new testClass({'key':'value'});
​test.test();​