Created
August 9, 2017 15:37
-
-
Save twxia/3fe0133f96ba3e55ef8db35516f25386 to your computer and use it in GitHub Desktop.
This file contains 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
1. IIFE, 為了避免污染全域的環境,然後此 funciton 當他建構好後又會立即的執行。 | |
2. 忽略了 javascript closure 的特性, 可以用 let 定義一個新變數,值為 i 。又或者是把 ajax call 那邊建立一個 funciton,把 i 傳入的方式,避免掉 closure。 | |
3. CDN,減少自身流量,快速 (依使用者位置,對應局離近的伺服器。或有可能使用者有 cache 了)等好處大於放本機端。 | |
4. 因為 bind 在 IE8 沒支援,我們可以利用 apply 模擬出類似的作法,簡單方式像以下,也可以用 polyfill 來處理 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) | |
``` | |
function bind(fn, obj){ | |
return function(){ | |
fn.apply(obj, arguments); | |
} | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment