我刚刚进入jQuery插件,我想用一个准系统面向对象的插件模板做一种'hello world'练习。但是我无法在下面的setup()函数中获取console.log语句以在Firebug控制台窗口中显示。新手jQuery插件问题
我所说的插件,像这样:
<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);
就像我说的,在设置()函数不显示的console.log语句。我不知道为什么。但是,如果我把一个的console.log语句紧随顶线,例如,它的工作:
;(function($) {
console.log('hello world');
.....有人可以告诉我,我做错了什么?