Hi-
I'm just getting into jQuery plugins and I wanted to do a sort of 'hello world' exercise with a barebones object-oriented plugin template. But I can't get the console.log statement in the setup() function below to display in a firebug console window.
I call the plugin like so:
<script type="text/javascript" src="myPlugin.js" >
<script type="text/javascript">
$(document).ready() {
$('ul').myPlugin();
});
</script>
myPlugin.js:
;(function($) {
$.fn.extend({
myPlugin: function(options) {
return this.each(function() {
new $.MyPlugin(this, options);
});
}
});
$.MyPlugin = function(element, options) {
var defaults = {
helloText: "hello World"
}
this.options = $.extend({}, defaults, options || {});
this.setup();
};
$.extend($.MyPlugin.prototype, {
setup: function() {
console.log(this.helloText);
}
});
})(jQuery);
Like I said, the console.log statement in the setup() function doesn't display. I have no idea why. However, if I put a console.log statement immediately following the top line, for example, it does work:
;(function($) {
console.log('hello world');
.....Can someone please tell me what I'm doing wrong?