0

Possible Duplicate:
jslint error: Unexpected 'in'. Compare with undefined, or use the hasOwnProperty

Why jslint complains about this code and how should I fix it.

            if ('children' in object) {
                for (key in object.children) {
                    recurse(object.children[key], key);
                }
            }

Obviously recurse is defined.

Community
  • 1
  • 1
Lorraine Bernard
  • 13,000
  • 23
  • 82
  • 134

1 Answers1

1

You are missing a var. Also, you are not using "hasOwnProperty".

if (object.hasOwnProperty('children')) {
    for (var key in object.children) {
        if(object.children.hasOwnProperty(key)) {
            recurse(object.children[key], key);
        }
    }
}
Display Name
  • 448
  • 2
  • 5
  • 14