Hey guys, I got an error in javascript and it won't get away. :-) In the little recursive thingy following, I want to replace a value inside a (nested) object.
var testobj = {
'user': {
'name': 'Mario',
'password': 'itseme'
}
};
updateObject('emesti', 'password', testobj)
function updateObject(_value, _property, _object) {
for(var property in _object) {
if(property == _property) {
_object[property] = _value;
}
else if(objectSize(_object) > 0) {
updateObject(_value, _property, _object[property]);
}
}
return _object
};
function objectSize(_object) {
var size = 0, key;
for (key in _object) {
if (_object.hasOwnProperty(key)) size++;
}
return size;
};
After running this, firefox throws the exception "too much recursion" on the line else if(objectSize(_object) > 0) {
.
Edit: if I set
function updateObject(_value, _property, _object) {
for(var property in _object) {
if(property == _property) {
_object[property] = _value;
}
else if(_object[property].hasOwnProperty(_property)) {
updateObject(_value, _property, _object[property]);
}
}
return _object
};
it works, but it only searches one level. If I had an nested object inside a nested object, it wouldn't work.
Any more ideas? (Thanks for the effort so far)
Edit: This problem occurs in Firefox 3.6. It works in Chrome.