elink12, еще вариант с полноценным джеквери бойлепрелтом.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<script>
;(function ( $, window, undefined ) {
var pluginName = 'Plugin',
document = window.document,
defaults = {
propertyName: "value"
};
function Plugin( element, options ) {
this.element = element;
this.options = $.extend( {}, defaults, options) ;
this._defaults = defaults;
this._name = pluginName;
this.init();
}
Plugin.prototype = {
init: function (e) {
*!*
$(this.element).click($.proxy(this.click, this));
*/!*
},
click : function(){
console.log(this.options);
}
};
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Plugin( this, options ));
}
});
};
}(jQuery, window));
$(function() {
$('#alert').Plugin({color:'green'});
$('#alert1').Plugin({color:'red'});
});
</script>
<div id='alert'>alert</div>
<div id='alert1'>alert1</div>
</body>
</html>