cowboy / jquery-hashchange

This jQuery plugin enables very basic bookmarkable #hash history via a cross-browser HTML5 window.onhashchange event.
http://benalman.com/projects/jquery-hashchange-plugin/
GNU General Public License v2.0
1.21k stars 258 forks source link

make it possible to be module #49

Open zba opened 8 years ago

zba commented 8 years ago

in case of use browserify it fail with 'Cannot use 'in' operator to search for 'onhashchange' in undefined' because window is undefined. this patch fixes it.

Krinkle commented 8 years ago

Maybe it should use window instead?

Anything using Function for evaluating code to global "this" is imho sufficiently far way from any responsible coding standard that I can't consider it.

Perhaps it makes more sense to simply pass window here since this jQuery plugin has no sensible use case outside a browser environment (unlike jQuery core, for example).

For comparison, jQuery core settled on the following https://github.com/jquery/jquery/pull/1476:

typeof window !== "undefined" ? window : this
zba commented 2 weeks ago

Oh, 9years ago. No, you shall not set it like is your comment, because that shall guarantee, that you not in binded function, correct way is to create function and return "this". I think eval was made to worship linter.