;(function($, window, document,undefined) {
var Beautifier = function(ele, opt) { //创建对象
this.$element = ele, //接受jq对象
this.defaults = { //默认参数
'color': 'red',
'fontSize': '12px',
'textDecoration': 'none'
},
this.options = $.extend({}, this.defaults, opt) //传递的参数和默认参数合并
}
Beautifier.prototype = { //对象添加方法
beautify: function() {
return this.$element.css({
'color': this.options.color,
'fontSize': this.options.fontSize,
'textDecoration': this.options.textDecoration
});
}
}
$.fn.myPlugin = function(options) { //把对象的方法添加到jquery方法中
var beautifier = new Beautifier(this, options); //外部传进jq对象和用户配置
return beautifier.beautify(); //调用对象方法
}
})(jQuery, window, document);