How does jQuery achieve making $ an alias for the jQuery function? -


i’m having little trouble wrapping head around $ sign being alias jquery function, particularly in plugin. can explain how jquery achieves aliasing: how define '$' alias jquery function? that's first question.

secondly, can explain how/why following code works map '$' jquery function in plugin's definition , why if don't this, plugin collide other libraries might use dollar sign?

(function( $ ){     $.fn.myplugin = function() {         // awesome plugin stuff here     }; })(jquery); 

a function, object in javascript, can assigned variable. variable can have name (that follows js variable naming rules). "$" satisfies naming rules, jquery function aliased "$" brevity. consider following example:

var myfn = function() { alert('myfunc'); }; var $ = myfn;  $(); // alerts 'myfunc' 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -