Can I add any random attribute to \'window\' object in javascript? Some thing like:
window.my_own_attr = \"my_value\"
Does it have any side
In all browsers, window
is the javascript global namespace. Every property or method 'lives' in that namespace. So if you assign a property to window
, it is in effect a global variable.
example:
window.myConstant = 5;
function multiply(val){
return myConstant * (val || 1);
}
multiply(10); //=> 50
multiply(); //=> 5
You have to be cautious with javascript frameworks. For instance, if you declare window.JQuery
, and use the JQuery
framework, the JQuery
namespace will be replaced by your assignment, rendering it useless.