JS: polyfill vs. shim vs. transpiler
先來看一下MDN對於polyfill的定義: A polyfill is a piece of code (usually JavaScript on the Web) used to provide modern functionality on older browsers that do not natively support it. Polyfill是由Remy Sharp所創造的名
Search for a command to run...
Articles tagged with #javascript
先來看一下MDN對於polyfill的定義: A polyfill is a piece of code (usually JavaScript on the Web) used to provide modern functionality on older browsers that do not natively support it. Polyfill是由Remy Sharp所創造的名
以前實習時候學到用barrel file管理模組,因為可以讓模組管理變得很一目了然、import的時候可以一行引入多個模組,所以工作後仍持續使用barrel file,結果後來才發現barrel file其實藏有蠻多潛在問題: 降低開發體驗 以Vite開發模式來說,即便只引用barrel file內其中一個模組,Vite在初始化的時候需要時間去解析和轉換barrel file裡面所有export出
因為工作都是在做地圖相關的web,很常需要取得使用者定位的功能;但如果直接使用瀏覽器原生的 Geolocation API,可能會碰到使用者拒絕定位存取權後,程式端無法再次詢問定位存取權的問題。 爬了一下文章,無法靠程式去修正使用者端瀏覽器的定位存取權設定,得靠使用者自己重新開啟應用的定位權限;但有時候會碰到使用者想要時而拒絕、時而開啟的問題,頻繁要求使用者開啟關閉存取權可能也會導致使用者體驗下降
Object protocol 物件協定 valueOf 多數情況下不要在 number 或 string 以外的型別使用 +、-、*、/、** valueOf 方法會回傳基本型別,可在需要基本型別運算時使用; valueOf 在 Date 實例可用於比較關係(>、<、>=、<=),但不建議用在 +、-、*、/、** 運算。 // ex0. 預設回傳instance本身 let o = {}; console.log(o.valueOf() === o); // true ...
基本語法 delete:刪除物件屬性 in:確認物件是否擁有某屬性 property in object 確認屬性值是否為 undefined→ 應用:option object,可避免屬性值為期他的 Falsy family (0、''、false、null): function has(obj, name){ return typeof obj[name] !== 'undefined'; } let obj = {x: undefined, y: 0}; c...
Closure 閉包 function 與 lexical environment (作用域環境) 的組合 free variable 函式捕捉的是變數,並非變數值。 var fs = []; for (var i = 0; i < 10; ++i){ fs[i] = function(){ return i; // 捕捉的是變數 i } } console.log(fs[0]()); // 10 console.log...