上次整理了Ajax部分,这周看完了高级技巧部分,也整理下吧。
function Person(name){ this.name = name; }
function Person(name){ if(this instanceof Person){ this.name = name; }else{ return new Person(name); } }
function createSomething(){ if(supportH5){ //do something }else{ //do otherthing } }
function createSomething(){ if(supportH5){ createSomething = function(){ //重写了createSomething 函数 //do something } }else{ //同上 } }
var i = 0; window.onresize = function(){ console.log(i++); }
var i = 0, j = 1; window.onresize = function(){ if(j % 2 == 0){ console.log(i++); } j++; }
function throttle(method , context){ clearTimeout(method.tId); method.tId = setTimeout(function(){ method.call(context); },100); }
原文:http://www.cnblogs.com/season-huang/p/3563885.html