maheshchari / js-hotkeys

Automatically exported from code.google.com/p/js-hotkeys
0 stars 0 forks source link

Plugin adds a bunch of unneccassary global variables #17

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
After executing the plugin, a bunch of new global variables are added to
the global (window) object, including version, special_keys, shift_nums and
more. To test this, run Firebug and enter one of those variables (or use
window.special_keys to be more explicit).

These global variables have been added due to the use of the "this" keyword
inside the plugin:

(function (jQuery){
    this.version = '(beta)(0.0.3)';
    ...
)(jQuery);

When a JavaScript function is called without being treated as a method the
"this" keyword refers to the global "window" object, and any properties
added to it will become global variables. This is bad!

The solution should be pretty straight forward. Since "this" appears to
just be used to collect some variables together in to an object, a
different variable could be substituted instead. I suggest something like this:

(function (jQuery){
    var hotkeys = {}
    hotkeys.version = '(beta)(0.0.3)';
    ...
    ...
    jQuery.hotkeys = hotkeys;
)(jQuery);

Original issue reported on code.google.com by simon%si...@gtempaccount.com on 4 May 2008 at 8:18

GoogleCodeExporter commented 8 years ago
fixed it in this module as well as adopted this approach in another project.
Thanks alot
(will upload new version soon).

Original comment by Afro.Sys...@gmail.com on 17 Aug 2008 at 6:40

GoogleCodeExporter commented 8 years ago

Original comment by Afro.Sys...@gmail.com on 24 Aug 2008 at 8:39