分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

js中use或者using方法

发布时间:2023-09-06 01:10责任编辑:苏小强关键词:js

看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方法

原文地址:http://www.cnblogs.com/coding4/p/7510867.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved