This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 算法本身 | |
for(var i = 0 ; i < arr.length - 1 ; i++){ | |
for(var ii = i + 1; ii < arr.length ; ii++){ | |
if(arr[i] > arr[ii]) | |
normalSwap(arr, i, ii); | |
} | |
} | |
// 利用了Mr.Async.Interpreter的方式 | |
eval(Mr.Async.recode(function(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 一个实现了Mr.Deferred的通用异步方法 | |
// 等待一秒钟,计算一个0到1的随机数 | |
function asyncRandom(callback){ | |
var de = Mr.Deferred(); | |
setTimeout(function(){ | |
var random = Math.random(); | |
if(typeof callback == 'function') | |
callback(random); | |
de.resolve(random); | |
}, 1000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eval(Mr.Async.recode(function(){ | |
var i = $await(delay()); // 等待 | |
console.log(i); | |
})); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
why is it not 100% perfect? | |
- because if you wanna override the parent's method to get the private variable and use | |
my way to extend, you can not get the right value. in this code, a example can be found | |
to demonstrate the right way to use extend method, in this example, is you change the 'title' | |
variable like this way 'var title' not 'this.title', finally you just get the undefined value | |
after invoking the getTitle on Child class instance. | |
- any question, contact me through http://sheldonw.sinaapp.com | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(['./lib/Mr.Async', './lib/Recoder/main'], function(Mr, interpreter){ | |
function asyncUpload(image){ | |
var dfd = Mr.Deferred(); | |
ajaxPost(image, function(ret){ | |
if(ret.status == 200){ | |
dfd.resolve(); | |
} | |
}); | |
return dfd; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(['./lib/Mr.Async', './lib/Recoder/main'], function(Mr, interpreter){ | |
function getListData(url, callback){ | |
$.get(url, callback, 'json'); | |
} | |
function getSideBarData(url, data, callback){ | |
$.get(url, data, callback, 'json'); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var outer = document.getElementById('outer'); | |
var inner = document.getElementById('inner'); | |
outer.addEventListener('click', function(evt){ | |
console.log(evt.target); | |
alert(0); | |
}, false); | |
inner.addEventListener('click', function(evt){ | |
console.log(evt.currentTarget); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function once(elem, eventType, handler){ | |
elem.addEventListener(eventType, function(evt){ | |
handler.call(elem, evt); | |
elem.removeEventListener(eventType, arguments.callee/*, false */); | |
}, false) | |
} | |
once(document.getElementById('onceButton'), 'click', function(evt){ | |
alert('just show once!'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var outer2 = document.getElementById('outer2'); | |
var inner2 = document.getElementById('inner2'); | |
var stopChecked = document.getElementById('stopChecked'); | |
outer2.addEventListener('click', function(evt) { | |
alert('outer click 1.'); | |
}, false); | |
inner2.addEventListener('click', function(evt) { | |
alert('inner click 1.'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Wikipedia explanation: http://zh.wikipedia.org/wiki/Git#.E5.91.BD.E5.90.8D.E6.9D.A5.E6.BA.90 |
OlderNewer