Created
September 26, 2014 02:14
-
-
Save iamblue/5bfb762feb5f7622d9c3 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
| //backcall | |
| $http.get("http://#{api}/test/all").success(function(json){ | |
| openFile(function(filename){ | |
| saveJsonToFile(filename, json); | |
| }); | |
| }) | |
| json <- $http.get "http://#{api}/test/all".success //json 從這裡來 | |
| filename <- openfile //filename 從這裡來 | |
| saveJsonToFile filename, json | |
| // 多個 | |
| $http.get("http://#{api}/test/all").success(function(json){ | |
| openFile(function(filename){ | |
| saveJsonToFile(filename, json); | |
| }); | |
| }) | |
| $http.get("http://#{api}/test2/all").success(function(json){ | |
| openFile(function(filename){ | |
| saveJsonToFile(filename, json); | |
| }); | |
| }) | |
| do | |
| json <- $http.get "http://#{api}/test/all".success //json 從這裡來 | |
| filename <- openfile //filename 從這裡來 | |
| saveJsonToFile filename, json | |
| do | |
| json <- $http.get "http://#{api}/test/all".success //json 從這裡來 | |
| filename <- openfile //filename 從這裡來 | |
| saveJsonToFile filename, json | |
| // loop scope | |
| for ( var i = 1; i <= 3; i++){ | |
| console.log(i); //這行跟上面的loop放在一樣的fn 記憶體之中 | |
| } | |
| // 1 2 3 | |
| for ( var i = 1; i <= 3; i++){ | |
| setTimeout(function(){console.log(i);},0) | |
| } | |
| // 10 10 10 | |
| for ( var i = 1; i <= 3; i++){ // => i 的 scope 是 global | |
| setTimeout(function(){console.log(i);},0) // => i 的 scope 是 local | |
| //因為這是另一個function 他被放在跟var i截然不同的記憶體之中 | |
| //因此當var 執行完畢後 進行下一輪記憶體讀取這條function時他這時候的scope是global的 10 | |
| } | |
| for ( var i = 1; i <= 3; i++){ // => i 的 scope 是 global | |
| setTimeout(function(){ console.log(i);}(i),0); // => i 的 scope 是 local | |
| //這代表不管怎樣強制執行這條function ,因此每次這條fn都會接到他所需要知道的 local scope variable | |
| } | |
| for (let i from 1 to 3) | |
| setTimeout -> | |
| console.log i | |
| , 0 | |
| // 恐怖的字串組在一起 | |
| var name = 'paul' | |
| var say = 'hello world'; | |
| 'hello this is' + paul + '_' + say | |
| // ls -> | |
| "hello this is #{name} _ #{say}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment