jeromeetienne / jquery-qrcode

qrcode generation standalone (doesn't depend on external services)
http://blog.jetienne.com/blog/2011/04/07/jquery-qrcode/
MIT License
4.85k stars 2.5k forks source link

.noConflict() compliance: only reference $, not jQuery, inside the closure #26

Closed jgoldberg closed 12 years ago

jgoldberg commented 12 years ago

According to the jQuery coding standards (http://wiki.jqueryui.com/w/page/12137737/Coding-standards), you shouldn't reference 'jQuery' inside the closure, only '$':

.noConflict() compliance

Wrap plugins in a closure that passes jQuery in as a parameter. Inside the closure, only reference jQuery through the parameter variable.

(function( $ ) { // inside here only reference $, not jQuery }( jQuery ) );

jeromeetienne commented 12 years ago

Can you explain the reasoning behind ? Why using jQuery is an issue ?

jgoldberg commented 12 years ago

Couple of examples for why you need noConflict() mode:

1) Not everyone can override $ with jQuery in their web applications. For example, people who have a legacy Prototype dependency, but want to use some jQuery features. So some people can only rely on jQuery('.item') instead of $('.item').

2) If you are writing a third-party library that uses jQuery, but the site that may be adding your library also might have their own jQuery implementation. So you need $ and MyLib.$ to coexist.

jeromeetienne commented 12 years ago

my bad, i first read the patch on my phone. my bad :)

merged, thanks for contributing!

jgoldberg commented 12 years ago

No problem, thanks for the plugin!