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);
}
}());

posted @ 2018-02-05 16:02  张书达  阅读(527)  评论(0编辑  收藏  举报