<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                [TOC] <br/><br/><br/> # <b style="color:#4F4F4F;">簡介說明</b> 原文鏈接: - [javascript的23種設計模式](https://mp.weixin.qq.com/s/hP5YMgJTgaVIlaK-XJ3Bcw) - [用了這個設計模式,我優化了50%表單校驗代碼](https://mp.weixin.qq.com/s/zGca0S0Xfs_D5ZSBPBXfXg) ``` 版本:JavaScript常見問題 作用:JavaScript常見問題 ``` <br/> # <b style="color:#4F4F4F;">常見問題</b> <br/> # <span style="color:#619BE4">實現類似python getattr動態屬性獲取?</span> ***** 實現類似python getattr動態屬性獲取 <br/> ### 示例內容 <span style="color:red">1. 解決代碼</span> ``` let x = new Proxy({}, { get(target, name) { return `Value for attribute ${name}` } }); console.log(x.lskdjoau); // produces message: "Value of attribute 'lskdjoau'" ``` <br/> # <span style="color:#619BE4">實現loadsh get方法?</span> ***** 實現loadsh get方法 <br/> ### 示例內容 <span style="color:red">1. 解決代碼</span> ``` function deepGet(object, path, defaultValue) { return (!Array.isArray(path) ? path.replace(/\[/g, '.').replace(/\]/g, '').split('.') : path) .reduce((o, k) => (o || {})[k], object) || defaultValue; } ``` <br/> # <span style="color:#619BE4">中文按照字母分隔并排序?</span> ***** 中文按照字母分隔并排序 <br/> ### 示例內容 <span style="color:red;">1. 解決代碼</span> ``` function pySegSort(arr, empty) { if (!String.prototype.localeCompare) { return null; } let letters = "*abcdefghjklmnopqrstwxyz".split(''); let zh = "阿八嚓噠妸發旮哈譏咔垃痳拏噢妑七呥扨它穵夕丫帀".split(''); let segments = []; let curr; letters.forEach((l, i) => { curr = {letter: l, data: []}; arr.forEach((content) => { // 內容大小在上一個文字和當前文字之間,是的話則上傳 if ((!zh[i - 1] || zh[i - 1].localeCompare(content, "zh") <= 0) && content.localeCompare(zh[i], "zh") === -1) { curr.data.push(content); } }) if (empty || curr.data.length) { segments.push(curr); curr.data.sort(function (a, b) { return a.localeCompare(b, "zh"); }); } }); return segments; } ``` <br/> # <span style="color:#619BE4">ArrayBuffer與字符串的互相轉換?</span> ***** ArrayBuffer與字符串的互相轉換 <br/> ### 示例內容 <span style="color:red;">1. 解決代碼</span> ``` // ArrayBuffer轉為字符串,參數為ArrayBuffer對象 function ab2str(buf) { return String.fromCharCode.apply(null, new Uint16Array(buf)); } // 字符串轉為ArrayBuffer對象,參數為字符串 function str2ab(str) { var buf = new ArrayBuffer(str.length*2); // 每個字符占用2個字節 var bufView = new Uint16Array(buf); for (var i=0, strLen=str.length; i<strLen; i++) { bufView[i] = str.charCodeAt(i); } return buf; } ``` <br/> # <span style="color:#619BE4">實現深拷貝?</span> ***** 如何實現深拷貝? <br/> ### 示例內容 <span style="color:red;">1. 解決代碼</span> ``` function cloneDeep(x) { const root = {} // 棧 const loopList = [ { parent: root, key: undefined, data: x } ] while (loopList.length) { // 廣度優先 const node = loopList.pop() const parent = node.parent const key = node.key const data = node.data // 初始化賦值目標,key為undefined則拷貝到父元素,否則拷貝到子元素 let res = parent if (typeof key !== 'undefined') { res = parent[key] = {} } for (let k in data) { if (typeof data[k] === 'object') { // 下一次循環 loopList.push({ parent: res, key: k, data: data[k] }) } else { res[k] = data[k] } } } return root } ``` <br/>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看