2014年10月29日 星期三

20141029 今日學習

讀到洪士灝老師一篇談科學研究、邏輯訓練、學術強者卻真井底之蛙,滿有趣的紀錄一下
偶然讀到一個講作業系統的投影片,做得滿不錯的
看到這個讓我想起以前曾看過Jserv的投影片,也是上傳到slideshare這網站,當初就在想上傳到這網站的slide可以弄動畫嗎,結論:果然可以,下次一定要來玩玩 XD

看到偉大的物理學家霍金,其生平故事改編電影,一定要看,太正了


閒談:剛剛估狗看到tumbler blog,讀這篇文章時看到Medium以及看了許久中於今天知道是什麼的logdown天啊,這兩個網站的畫面真的太正了,害我都想跳槽了,估狗部落格真是醜死了 XD

這操縱者太強大了!!!!     ‪#‎四足‬ ‪#‎怪手‬ ‪#‎媲美機械獸‬ ‪#‎再度跪在電腦面前‬


今日目標:先學完higher order function,再回去複習module patern,最後回去讀recursion
higher order function學習教材
forEach(array, action)
他是個JavaScript裡內建的function,你可以在forEach外面定義一個array與array裡面的element,然後把這個array放入forEach()的第一個parameter,第二個parameter是讓我們來寫一個function來執行對array要進行的操作,function(number){...},裡面的number就是我們array裡的element,就像傳統的寫for loop去操作arry,不過比傳統寫法更簡潔易讀
  • This looks quite a lot like the classical for loop, with its body written as a block below it. However, now the body is inside the function value, as well as inside the parentheses of the call to forEach. This is why it has to be closed with the closing brace and closing parenthesis.
  • Using this pattern, we can specify a variable name for the current element (number), rather than having to pick it out of the array manually.
forEach是JavaScript內定義的function,在此附上它的定義
Array.prototype.forEach = function(callback,thisObject) {};
由於尚未讀過CH4的two array-traversing loops,這篇用forEach改寫的讀不太懂,去找別篇資料繼續學習forEach

讀這篇時才知道Higher-order function又稱之為Callback function
這篇不錯,提到JavaScript的function是first-class object,所以function可以當作一個parameter傳入另一個function去
  • In JavaScript, functions are first-class objects; that is, functions are of the type Object and they can be used in a first-class manner like any other object (String, Array, Number, Object, etc.), since they are in fact objects themselves. They can be “stored in variables, passed as arguments to functions, created within functions, and returned from functions”1.
這篇提到一個term(專業術語),functional programming,Higher-order function被廣泛用於jQuery

喔喔喔,他提到forEach與Callback function時有順便講到Anoymous function的定義
  • anonymous function (a function without a name) 
原來我們只是傳function的定義當作另一個function的parameter
  • When we pass a callback function as an argument to another function, we are only passing the function definition. We are not executing the function in the parameter.

換個口味稍微略讀一下Eloquent JavaScript的Higher-Order Functions 這節,老實說寫得不好,沒抓到精隨,略讀後就打算直接跳過,繼續讀其他篇資料

這篇不錯,雖然標題是Higher-order function但是前面有很長一大串在討論Closure (第I與II節)
這篇文章很正的一點在於他討論了parentheses "()" 在JavaScript裡的用途,對於Higher-order function理論的解釋不多,但是解釋function與Closure非常之清楚,難怪JavaScript is Sexy要說Callback Functions Are Closures


疲勞了,剩下的明天再作業

沒有留言:

張貼留言