I have this code...
function a(options) {
for (var item in options) {
if ( ! options.hasOwnProperty(item)) {
continue;
}
this[item] = options[item];
}
}
a({ 'abc': 'def' });
Whilst this unpacks variables from the object, it sets them to global scope (attached to window
) because this
is window
in that circumstance.
So after the function I can do alert(abc)
and it will alert def
, which isn't good.
How would I set the scope of the variables to the function?