Created
November 25, 2013 13:08
-
-
Save jocoonopa/7640955 to your computer and use it in GitHub Desktop.
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
// 參考:http://dreamerslab.com/blog/tw/javascript-callbacks/ | |
function do_a ( callback ) { | |
setTimeout( function() { | |
// 模擬一個需要長間的 function | |
console.log( '`do_a`: 這個需要的時間比 `do_b` 長' ); | |
// 如果 callback 存在的話就執行他 | |
callback(); | |
}, 3000 ); | |
} | |
function do_b () { | |
console.log( '`do_b`: 現在我們就可以肯定 `do_b` 出現在 `do_a` 之後了' ); | |
} | |
do_a( function(){ do_b();} ); | |
// jQuery常用 | |
// $(function () {}); | |
// $( document ).ready( function () {} ); | |
// jQuery( document ).ready( function ( $ ) {} ); | |
(function ( x ) { | |
alert( x ); | |
})( 1 ); // (1)是群組運算子,不是函式呼叫 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment