js原生插件

// plugin.js
;(function(undefined) {
"use strict"
var _global;

function extend(o,n,override) {
for(var key in n){
if(n.hasOwnProperty(key) && (!o.hasOwnProperty(key) || override)){
o[key]=n[key];
}
}
return o;
}

function Plugin(opt){
this.init(opt);
}

Plugin.prototype = {
constructor: this,
init: function(opt){
var def = {

}
this.def = extend(def,opt,true);
}
};

// 最后将插件对象暴露给全局对象
_global = (function(){ return this || (0, eval)('this'); }());
if (typeof module !== "undefined" && module.exports) {
module.exports = Plugin;
} else if (typeof define === "function" && define.amd) {
define(function(){return Plugin;});
} else {
!('Plugin' in _global) && (_global.Plugin = Plugin);
}
}());

原文地址:https://www.cnblogs.com/zhangshuda/p/8417997.html