Are there any JS libraries that use $ in the same way as Jquery uses it? I searched all over the internet to my capabilities and i couldn't find any use cases where there is a possibility for conflict over the usage of $ in jquery.
Asked
Active
Viewed 58 times
-4
-
Why do that? You can just change the dollar with JQuery. http://stackoverflow.com/q/6746352/1577343 – Eduard Florinescu Jul 02 '14 at 05:12
-
MooTools library using $ variable – Syam Mohan M P Jul 02 '14 at 05:12
-
Possible duplicate of: http://stackoverflow.com/questions/4632041/what-javascript-libraries-are-known-to-use-the-global-dollar-sign-window – r0hityadav Jul 02 '14 at 05:18
-
Thank you for the link to similar question. I asked the question after spending 45 minutes searching for it. feels bad to have got this many down votes – Vivek Ananda Jul 02 '14 at 05:52
1 Answers
1
There really are quite a few. MooTools is one example, but there are many others as well. The $ character is used so frequently in JS shorthand because it very commonly has special significance in other programming languages, but is free from such associations in JS. So library developers will often use the $ character as a shortcut to their library.
This really isn't a big deal if you're writing well formatted JS. Any time you write a block of JS that relies heavily on a partiular library that uses a common shortcut, you should wrap it in an Immediately Invoked Function Expression that gives you full access to the shortcut while simultaneously preventing both conflicts and scope issues.
(function ($) {
// use the $ within this function with impunity.
// there is no danger of it conflicting with another library here.
$('body').doStuff();
})(jQuery);

Ben
- 316
- 1
- 7