09 2013 档案
摘要:1 function multistep(steps, args, callback){ 2 var tasks = steps.concat(); 3 4 setTimeout(function(){ 5 var task = tasks.shift(); 6 7 task.apply(null, args || []); // call / aplly 第一个参数是 null或者undefined的时候指向window 或者 Global 8 9 if(tasks.leng...
阅读全文
摘要:1 // 用定时器处理数组 2 var items = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]; 3 4 function processArray(items, process, callback){ 5 var todo = items.concat(); // 克隆原数组 6 7 setTimeout(function(){ 8 process(todo.shift()); // 取得数组的下个元素并进行处理 9 10 /...
阅读全文
摘要:1 var sub = document.getElementById("sub");2 sub.setAttribute("disabled", "disabled"); // 兼容的3 sub.setAttribute("style", "position:absolute;left:100px;top:100px;"); // IE 7 不能设置成功4 5 // 以下为兼容方法: 6 var cssText = "position:absolute;left:100px;top:
阅读全文
摘要:1 var a = 1; 2 function aa(){ 3 a = 2; 4 } 5 aa(); 6 console.log("a:", a); // 2 7 8 var b = 1; 9 function bb(){10 b = 2;11 var b = 3;12 }13 bb();14 console.log("b:", b); // 115 16 function foo(){17 var a1 = 1;18...
阅读全文
摘要:1 var i =0, count = 1; 2 3 // for 循环 跟 while循环 是一样的 可以互相转换 前测 4 /*while(i < 10){ 5 console.log("i is:", i); 6 i++; 7 }*/ 8 9 // A10 do{11 console.log("i::",i);12 13 console.log("count ---", count)14 count++;15 16 i+...
阅读全文
摘要:1 var btn = document.getElementById("btn"), show = document.getElementById("content"), count = 0; 2 btn.onmouseover = function(){ 3 console.log(this) 4 this.style.cssText = "cursor : pointer;"; 5 }; 6 btn.onclick = function(e){ 7 console.log(count); 8 if(...
阅读全文
摘要:1 ;(function(global){ 2 var wind = document.getElementById("wind"), count = 0; 3 4 function marque(){ 5 console.log("wind.offsetTop:",wind.offsetTop,"wind.offsetLeft::",wind.offsetLeft); 6 7 8 /*wind.style.left = 12 + wind.offsetLeft + "px"; 9 ...
阅读全文
摘要:1 2 Styoo 3 Junior 4 5 月落乌啼霜满天,江风渔火对愁眠。 6 7 8 var data = [ 9 {10 "name" : "Nicolas",11 "url" : "http://wwww.baidu.com"12 },13 {14 "name" : "Rose",15 "url" : "http://tmall.com"16 }17 ...
阅读全文
摘要:1 // 读取一个集合的length 比一个普通的数组要慢很多 2 function toArray(coll){ 3 for(var i = 0, a= [],len = coll.length; i < len; i++){ 4 a[i] = coll[i]; 5 } 6 return a; 7 } 8 // 将HTML 转化为普通数组 9 function convertToArray(nodes){10 var arr = [];11 try{12 ...
阅读全文
摘要:1 /* 2 * 回调函数: 执行一个函数 A 的时候 有可能执行另外的函数B ,这个 B 就是回调函数 3 * call apply 4 * 可以调用其他的方法 ,并且改变 this 的指向 5 */ 6 7 var found = document.getElementById("outer"); 8 9 var myApp = {};10 myApp.color = "green";11 myApp.paint = function(node){12 node.style.color = t...
阅读全文
摘要:1 function Universe() { 2 //缓存实例 3 var instance = this; 4 5 // 重写构造函数 6 Universe = function(){ 7 return instance; 8 }; 9 10 this.start_time = 0;11 this.bang = "Big";12 13 //保留原型属性14 Universe.prototype = thi...
阅读全文
摘要:1 function Universe() { 2 //缓存实例 3 var instance = this; 4 5 this.start_time = 0; 6 this.bang = "Big"; 7 8 Universe = function(){ 9 return instance;10 };11 }12 13 //var uni = new Universe();14 //var uni2 = new Universe();15 ...
阅读全文
摘要:1 2 3 4 5 借用方法/ 绑定 6 9 10 11 12 68 69
阅读全文
摘要:1 /* 2 借用构造函数 3 */ 4 5 //Article 6 function Article(){ 7 this.tags = ["js", "css"]; 8 } 9 Article.prototype.getTags = function(){10 return this.tags;11 };12 13 var article = new Article();14 15 //BlogPost16 function BlogPost(){}17 18 ...
阅读全文