I use Aptana to write JS and I recently installed jQuery bundle (mostly for code-completion but also for new cool things that I do not know).
So when I type ready and press Ctrl + <Space> I get two options, document ready and document ready (safe) choosing one of which will automatically put $(document).ready(function(){}) or jQuery(document).ready(function($){}) respectively.
But that is irrelevant. When I use $(someElement).cl the code-completion feature gives me the option click and when I select it it puts down the following code for me:
$(someElement).click(function() {
${0:
\}});
(It's relevant. I'll talk about it later)
Similarly, I was trying to write a plugin and I typed plugin and pressed Ctrl + <Space> and selecting the option plugin (method) I got the following code:
;(function($) {
}
$.fn.pluginName = function(options) {
var opts = $.extend({}, $.fn.pluginName.defaults, options);
return this.each(function() {
var $this = $(this);
${6:
var o = $.meta ? $.extend({\}, opts, $this.data()) : opts;
}
});
// private function for debugging
function debug($obj) {
if (window.console && window.console.log) {
window.console.log($obj);
}
}
};
// default options
$.fn.pluginName.defaults = {
defaultOne:true,
defaultTwo:false,
defaultThree:'yay!'
};
})(jQuery);
First of all, as far as I know, a common method of writing a plugin goes like this
(function($) {
$.fn.plugin = function(args) {
//...
}
})(jQuery);
And I can define defaults as $.fn.plugin.defaults = {...} or just var defaults = {...} inside my plugin and in my plugin, extend a {} with defaults and args. That's just about all I am familiar with.
So:
- Why does Aptana jQuery bundle put a
;in the very beginning? - Why does it close the
function($){}before$.fn.pluginName? - And most of all, what is this
${0:in the$.click()example and${6:inplugin (method)example? - Also, what indeed is
$.metaand$this.data()?
It's all very confusing (yet, strangely exciting)...