too much recursion
Posted
by Dänu
on Stack Overflow
See other posts from Stack Overflow
or by Dänu
Published on 2010-05-29T16:10:56Z
Indexed on
2010/05/29
16:12 UTC
Read the original article
Hit count: 338
JavaScript
|recursion
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) {
.
© Stack Overflow or respective owner