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
Post a Comment