The loop for..initerates over enumerated properties obj. Functions are objects, they have their own properties plus inherited properties from the [[prototype]] chain. See ECMA-262 §12.6.4.
Also, be sure to declare variables that should be stored locally.
To address only enumerated properties in obj, rather than its inherited enumerated properties, usually include the hasOwnProperty test:
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
// key is enumerable property of obj, not inherited
}
}