Skip to content

Instantly share code, notes, and snippets.

@jocoonopa
Created November 25, 2013 13:08
Show Gist options
  • Save jocoonopa/7640955 to your computer and use it in GitHub Desktop.
Save jocoonopa/7640955 to your computer and use it in GitHub Desktop.
// 參考: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