js中use或者using方法

來源:互聯網
上載者:User

標籤:const   property   split   i++   oca   htm   .json   ati   return   

看Vue.use方法,想起了以前工作中別人用過的use方法。

var YANMethod = {    using:function() {        var a = arguments, o = this, i = 0, j, d, arg, isExist;        arg = a[0], isExist = a[1];        if (arg && arg.indexOf(‘.‘)) {            d = arg.split(‘.‘);            for (j = (d[0] == ‘YAN‘) ? 1 : 0; j < d.length; j++) {                if(!o[d[j]] && isExist) return null;                o[d[j]] = o[d[j]] || {};                o = o[d[j]];            }        } else {            o[arg] = o[arg] || {};        }        return o;    },    /*--        用新Cookie方法,但是相容老的東西        -ver 2014-04-22    */    cookie:function(name, value, options) {        if(typeof value===‘undefined‘){            return Cookie.get(name);        }        if(options){            options.exp = typeof options.expires===‘number‘ ? options.expires * 24 :                options.expires; //原來的cookie是按天算的        }        Cookie.set(name, value, options);    },        /**     *JSON序列化,如果傳入的是字串則還原序列化為對象;若傳入的是對象則還原序列化為字串     */    json:function(value){        if(typeof value==="string"){            return this.jsontoObject(value);        }else{            return this.jsontoJSON(value);        }    },    jsontoJSON:function(object){        var type = typeof object;        if (‘object‘ == type) {            if (Array == object.constructor) type = ‘array‘;            else if (RegExp == object.constructor) type = ‘regexp‘;            else type = ‘object‘;        }        switch (type) {            case ‘undefined‘:            case ‘unknown‘:                return;            break;            case ‘function‘:            case ‘boolean‘:            case ‘regexp‘:                return object.toString();            break;            case ‘number‘:                return isFinite(object) ? object.toString() : ‘null‘;            break;            case ‘string‘:                return ‘"‘ + object.replace(/(\\|\")/g, "\\$1").replace(/\n|\r|\t/g, function() {                    var a = arguments[0];                    return (a == ‘\n‘) ? ‘\\n‘: (a == ‘\r‘) ? ‘\\r‘: (a == ‘\t‘) ? ‘\\t‘: ""                }) + ‘"‘;            break;            case ‘object‘:                if (object === null)                     return ‘null‘;                var results = [];                for (var property in object) {                    var value = this.jsontoJSON(object[property]);                    if (value !== undefined)                         results.push(this.jsontoJSON(property) + ‘:‘ + value);                }                return ‘{‘ + results.join(‘,‘) + ‘}‘;            break;            case ‘array‘:                var results = [];                for (var i = 0; i < object.length; i++) {                    var value = this.jsontoJSON(object[i]);                    if (value !== undefined)                         results.push(value);                }                return ‘[‘ + results.join(‘,‘) + ‘]‘;            break;        }    },        jsontoObject:function(strjson){        return eval("(" + strjson + ")");    }};var addFunToYAN = function(functionName,func){    if(typeof(func) == ‘function‘)        YAN[functionName] = func;};for(var m in YANMethod){    if(typeof(YAN[m]) == ‘undefined‘){        addFunToYAN(m,YANMethod[m]);    }}$.extend(YAN.using("Plugin"),{});$.extend(YAN.using("Utils"),{    getQuery:function(name){          var paramList = location.search.replace("?","").split("&");          for(var i = 0 ; i < paramList.length ; i++)          {              if(paramList[i].split("=")[0] == name){                  return paramList[i].substring(paramList[i].indexOf("=") + 1,paramList[i].length);              }          }          return null;    }});var Plugin = YAN.using(‘Plugin‘);Plugin.AD = ad;Plugin.AD.getFlashAd();window.AD || (window.AD = YAN.using(‘Plugin‘).AD);

Vue.use()

http://www.cnblogs.com/dupd/p/6716386.html

js中use或者using方法

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.