javascript underscore library _.defer() sample

function gogogo(arg,scope) {
document.write(scope + arg + ‘<br />’);
}

var ori = “AAA”;
var dest = “BBB”;
gogogo(“first”,ori);

setTimeout(function() {
gogogo(“setTimeout”,ori);
},1);

_.defer(function() {
gogogo(“defer”,ori);
setTimeout(function() {
gogogo(“setTimeout2”,ori);
},1);
ori = dest;
});

gogogo(“last”,ori);

결과 :

AAAfirst
AAAlast
AAAsetTimeout
AAAdefer
BBBsetTimeout2

 

테스트:
https://jsfiddle.net/7t2bV/59/

Leave a Reply

Your email address will not be published. Required fields are marked *