自定义js封装

    技术2022-07-14  77

    网上搜索了很多,一顿整合,目前觉得比较合适的 才用 闭包 + 原型模式   结构记录如下 :

    ;(function(undefined){ 'use strict'; var _global; var defaultSetting = { }; var tools={}; var checkbox = function (settings){ if(!(this instanceof checkbox)){return new checkbox()}; var that = this; that.setting = $.extend(true,{},defaultSetting,settings); this.init(); tools.getName(); }; tools = { getName:function(){ return "123"; } }; checkbox.prototype = { constructor: this, init:function(){ }, getName:tools.getName } // 将插件对象暴露给全局对象(考虑兼容性) _global = (function(){ return this || (0, eval)('this'); }()); if (typeof module !== "undefined" && module.exports) { module.exports = checkbox; } else if (typeof define === "function" && define.amd) { define(function(){return checkbox;}); } else { !('checkbox' in _global) && (_global.checkbox = checkbox); } }());

     

    Processed: 0.014, SQL: 9