js中use或者using方法
看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方法的更多相关文章
- node.js中的url.parse方法使用说明
node.js中的url.parse方法使用说明:https://blog.csdn.net/swimming_in_it_/article/details/77439975 版权声明:本文为博主原创 ...
- JS中 call() 与apply 方法
1.方法定义 call方法: 语法:call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 说明: call ...
- JS中定义类的方法
JS中定义类的方式有很多种: 1.工厂方式 function Car(){ var ocar = new Object; ocar.color = "blue" ...
- js中this和回调方法循环-我们到底能走多远系列(35)
我们到底能走多远系列(35) 扯淡: 13年最后一个月了,你们在13年初的计划实现了吗?还来得及吗? 请加油~ 主题: 最近一直在写js,遇到了几个问题,可能初入门的时候都会遇到吧,总结下. 例子: ...
- js中object的申明方法
//js中的对象申明使用new Object(); //object类型的数据类似于数组通过下表来访问其中的值 //example1 var person=new Object(); person.n ...
- JS中令人发指的valueOf方法介绍
彭老湿近期月报里提到了valueOf方法,兴致来了翻了下ECMA5里关于valueOf方法的介绍,如下: 15.2.4.4 Object.prototype.valueOf ( ) When the ...
- js 中读取JSON的方法探讨
方法一:函数构造定义法返回 var strJSON = "{name:'json name'}"; //得到的JSONvar obj = new Function("r ...
- JS中定义类的方法<转>
转载地址:http://blog.csdn.net/sdlfx/article/details/1842218 PS(个人理解): 1) 类通过prototype定义的成员(方法或属性),是每个类对象 ...
- js中push和join方法使用介绍
push和join方法想必大家并不陌生吧,在本文将为大家详细介绍下js中的push和join方法的使用.代码: <script type="text/javascript"& ...
- prototype.js中Function.prototype.bind方法浅解
prototype.js中的Function.prototype.bind方法: Function.prototype.bind = function() { var __method = this; ...
随机推荐
- Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) E: Unable to lock the administration di
alexander@alexander-virtual-machine:~$ sudo apt-get install -y httpdE: Could not get lock /var/lib/d ...
- 20145308 《网络对抗》 注入shellcode+Return-to-libc攻击 学习总结
20145308 <网络对抗> 逆向及BOF进阶实践 注入shellcode+Return-to-libc攻击 学习总结 实践目的 注入shellcode 实现Return-to-libc ...
- host文件的作用
什么是host文件 Hosts是一个没有扩展名的系统文件,其基本作用就是将一些常用的网址域名与其对应的IP地址建立一个关联“数据库”,当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从Host ...
- 【python002-设计小游戏】
用python设计第一个游戏 一.运行idle的快捷方式:F5 二.首先设计一款小游戏: print('-------开启python学习之旅--------')temp = input(" ...
- ECharts公共组件:title详解、 tooltip详解、toolbox详解、legend详解、dataZoom详解、visualMap全解
1. Title mytextStyle={ color:"#333", //文字颜色 fontStyle:"norm ...
- Bootstrap3基础 list-inline 无序列表横向显示
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- 配置Codeblocks
1.安装mingw 官网:http://www.mingw.org/找到左边Navigation里面的Download(选择下图第一个即可,安装管理器,可自己手动选择要安装的组件)下图是安装管理器界面 ...
- (zhuan) Paper Collection of Multi-Agent Reinforcement Learning (MARL)
this blog from: https://github.com/LantaoYu/MARL-Papers Paper Collection of Multi-Agent Reinforcemen ...
- 最小 base64 图片
http://www.webhek.com/post/base64-encode-of-1x1px-transparent-gif.html Base64 Encode 1x1px透明GIF图片 Ba ...
- 6、nginx的反向代理及缓存功能
nginx模块的应用 ngx_http_proxy_module nginx 反向代理模块: http://nginx.org/en/docs/http/ngx_http_proxy_module. ...