第一个基础文件 名字是base.js
2012-01-13 21:18
323 查看
2012-01-13
base.js
This is the first version for my javascript lean.
I need learn more .
(function(window,undefined){ var _toString = {}.toString, _is, _writeScript, _listUrl, alfred = { author : "alfred", version : 1.01, global : this, doc : this.document, reset : function(it){this.global[it]=alfred;}, log : function(){if(window.console && console.log){return console.log(arguments)}}, isNumber : function(it){return _is(it,"Number")}, isString : function(it){return _is(it,"String")}, isFunction : function(it){return _is(it,"Function")}, isObject : function(it){return _is(it,"Object")}, isArray : function(it){return _is(it,"Array")}, isBoolean : function(it){return typeof it ==='boolean'}, scriptMap : { method_url : {},// method --> url < method : url > < 1 : 1 > url_method : {},// url --> method < url : [method,method] > < 1 : n > visited : {}, writted : {}, wait_write:[] }, require : function(method){ var m2u = this.scriptMap.method_url, u2m = this.scriptMap.url_method, r; if (!this.scriptMap.visited[m2u[method][0]] && !this.scriptMap.writted[m2u[method][0]]) { //haven't be visited or write this.scriptMap.visited[m2u[method][0]] = true; //use an beautiful code in here for(; m2u[method][1].length &&(r=m2u[method][1].shift());) { require(r); } _listUrl(); }; }, setMethod : function(url,method,rely){ if (url && method && !this.scriptMap.url_method[url]){ this.scriptMap.url_method[url] = method; for (var i = method.length - 1; i >= 0; i--) { this.scriptMap.method_url[method[i]] = {"0" : url, "1" : rely}; } } }, extend : function(){ var deep = false, len, options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1; len = arguments.length; if (!len) { return this; } if(alfred.isBoolean(target)) { deep = arguments[0]; to = arguments[1]; i = 2; } if (!(alfred.isObject(target) || alfred.isFunction(target))) { target = {}; } if (len = i) { to = this; --i; } for (;i<len;i++) { if ((options=arguments[i])!==null) { for (name in options) { copy = options[name]; src = target[name]; if (copy===target) {continue} if (deep && copy && (alfred.isObject(copy) || (copyIsArray = alfred.isArray(copy)))) { if (copyIsArray) { copyIsArray = false; clone = src && alfred.isArray(src) ? src : []; } else { clone = src && alfred.isObject(src) ? src : []; } target[ name ] = alfred.extend( deep, clone, copy ); } else if ( copy !== undefined ) { target[name] = copy; } }; }; }; } }; _is = function(it,type){ return _toString.call(it).toLowerCase()==="[object "+type.toLowerCase()+"]"; }; _listUrl = function(){ var l = alfred.scriptMap.visited,i; for(i in l){ alfred.scriptMap.wait_write.push(i); } alfred.scriptMap.wait_write.reverse(); _writeScript(); }; _writeScript = function(){ var head = document.getElementsByTagName("head").item(0); for (var i;alfred.scriptMap.wait_write.length&&(i=alfred.scriptMap.wait_write.shift());) { var script = document.createElement("script"), url = i || ""; script.setAttribute("async",true); script.setAttribute("type","text/javascript"); script.setAttribute("src",url); head.appendChild(script); alfred.scriptMap.writted[url] = true; }; }; $ = alfred; window.$ = $; })(window)
base.js
This is the first version for my javascript lean.
I need learn more .
相关文章推荐
- JavaSE8基础 File listFiles 分别获取指定文件夹下的第一层文件和文件夹的名字
- Python3基础 os listdir() 列举当前目录的所有文件及文件夹的名字
- win nodejs下 findit只返回第一个文件问题
- webpack1-打包js,并建立第一个配置文件
- asp.net中使用js找到后台该别IFRAME标签的网页的文件路径及名字
- less/sass 基础base文件
- Phaserjs基础教程第四节:加载音频、视频文件
- C#控制台基础 directory获取一个文件夹下所有文件夹的名字(不包含文件)
- 如何在js文件中如何获取basePath
- libevent基础文件event-internal.h(struct event_base结构体)
- JS基础及编写第一个JS程序
- 在BaseWidget.js中定义的变量appConfig可以表示全局的文件config.json
- 7、ExtJs——Ext基础架构--动态加载js文件--很重要
- Node.js(window)基础(1)——用cmd命令行访问某一文件夹下的js文件
- JS基础:1.3 引用JS文件
- Python3基础 os listdir curdir查看当前工作目录的所有文件的名字
- 在SSH的基础上使用jquery.uploadify.js上传文件
- 后缀就扩展名为js的文件是什么文件[原创]_基础知识_脚本之家
- Ext JS学习第十天 Ext基础之动态加载JS文件(补充)
- easyUI引用必要的css,js文件示例 基础(三)--cdn