<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 楊詠翔(Vibrissa) on Medium]]></title>
        <description><![CDATA[Stories by 楊詠翔(Vibrissa) on Medium]]></description>
        <link>https://medium.com/@vibrissa-yang?source=rss-604820524055------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fd3cjt40zaZkQbP9KYRTbA.png</url>
            <title>Stories by 楊詠翔(Vibrissa) on Medium</title>
            <link>https://medium.com/@vibrissa-yang?source=rss-604820524055------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 00:08:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vibrissa-yang/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[WebAssembly比想像的離你還近 — 之前端QRCode掃描]]></title>
            <link>https://medium.com/%E6%BC%B8%E5%BC%B7%E5%AF%A6%E9%A9%97%E5%AE%A4-crescendo-lab-engineering-blog/webassembly%E6%AF%94%E6%83%B3%E5%83%8F%E7%9A%84%E9%9B%A2%E4%BD%A0%E9%82%84%E8%BF%91-%E4%B9%8B%E5%89%8D%E7%AB%AFqrcode%E6%8E%83%E6%8F%8F-e52d8a286d6d?source=rss-604820524055------2</link>
            <guid isPermaLink="false">https://medium.com/p/e52d8a286d6d</guid>
            <category><![CDATA[webassembly]]></category>
            <category><![CDATA[engineering-blog]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[forntend]]></category>
            <dc:creator><![CDATA[楊詠翔(Vibrissa)]]></dc:creator>
            <pubDate>Fri, 18 Jun 2021 08:15:14 GMT</pubDate>
            <atom:updated>2021-07-01T01:36:13.686Z</atom:updated>
            <content:encoded><![CDATA[<h3>WebAssembly 比想像的離你還近 — 之前端 QRCode 掃描</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*lDQXkut_nNDN50j-PLCSRA.jpeg" /></figure><h3>前言</h3><p>WebAssembly 或稱 wasm 是一個實驗性的低階程式語言，應用於瀏覽器內的客戶端，可以在前端的世界裡<strong>以接近原生應用的效能執行。</strong>C/C++/Rust 編譯過後的 bytecode 在執行上有很高的執行效率，以往受限於效能而比較難做到的應用也能夠實現。</p><p>近年來，學習與使用 WebAssembly 對於前端工程師來說是一種趨勢。<br>雖然 WebAssembly 還在發展階段，並且有著無法直接操作 DOM的痛點，但有一些產品已經利用 WebAssembly 來建立一些“重度”應用，並利用 Canvas 來 Render 介面來避開上述痛點。</p><p>在這之前，你很難想像你可以在網頁上可以看到 Figma 這種以往都要下載 APP 的應用，把類似於 Sketch 的 整套功能直接搬到網頁上，並且提供十分良好的效能與體驗。</p><h3>先來看看成果</h3><p>這次跟同事 Simon 在工作上接到了一個客戶的需求，簡單來說這個功能就是要能在 Line Liff 網頁上開啟相機掃描客戶提供的保固 QRCode。以此為基礎做出保固的登錄。</p><p>與 Simon 討論後，我們決定使用 WebAssembly 的 QRCode 辨識套件來實作。廢話不多說，讓我們來看看成果。</p><p>下面是當初在React專案中實驗 WebAssembly Demo 的影片，這邊附上 <a href="https://github.com/Vibrissa/reactWASM">repo連結</a>，大家可以直接去 github 載來玩看看。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*ATEl_K-YJkgxFkj6AWkaIw.gif" /></figure><h3>技術背景</h3><p>實踐上述功能需要了解四項相關的技術背景</p><blockquote>WebRTC API</blockquote><blockquote>中文譯為”網路即時通訊技術”，可以提供任何瀏覽器在不需要安裝外掛程式或第三方軟體下，進行錄影或隨選播放串流音訊與影像的技術。</blockquote><p>WebRTC 主要提供兩個主功能：</p><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Media_Streams_API">Media Capture and Streams API (MediaStreams API)</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection">Peer to peer connection (RTCPeerConnection)</a></li></ul><p>透過 MediaStreams API 就可以在瀏覽器取得存取攝影機的權限後，透過攝影機的串流來丟給影像辨識的套件來偵測畫面中的條碼。</p><blockquote>Canvas API</blockquote><blockquote>可以用來繪圖、合成圖照片、建立動畫、甚至處理即時的影片播放。用作顯示攝影機的串流，協助使用者透過影像拍攝條碼操作掃描條碼的行為。</blockquote><blockquote>Web Workers</blockquote><blockquote>讓網頁 Javascript 獨立在背景執行而不會影響到原來的 HTML頁面，透過這個技術可以讓網頁的執行緒不會因為在偵測條碼的過程中，因計算偵測條碼而造成用戶畫面的卡頓發生。</blockquote><p>簡單說就是讓你可以在網頁擁有影分身之術的能力</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*ulb2GjKdbJO4pR28_deXCQ.jpeg" /></figure><blockquote>WebAssembly</blockquote><blockquote>WebAssembly 或稱 wasm 是一個實驗性的低階程式語言，應用於瀏覽器內的客戶端 (from wiki)<br>可以在前端的世界裡<strong>以接近原生應用的效能執行</strong>，C/C++/Rust 編譯過後的程式碼執行有很高的執行效率，受限於效能而比較難做到的應用也能夠實現。</blockquote><p>現在很多的語言也能透過轉譯後，編譯成 WebAssembly 能夠執行的程式，像是 python 的 <a href="https://github.com/pyodide/pyodide">pyodide</a> 可以在前端使用 pandas 操做一些 javascript 很難操作的運算，諸如此類的專案<a href="https://github.com/mbasso/awesome-wasm">不勝枚舉</a>，非常值得關注這項技術的後續發展。</p><h3>Code 與 React &amp; Vue 的環境設定</h3><p>首先我們必須先透過 WebRTC API 取得攝影機的串流並串到 Video Element上，這邊有個小細節可以注意一下。</p><blockquote><strong><em>video: { facingMode: “environment” }</em></strong></blockquote><p>這樣設定在手機上才會開啟後鏡頭，否則預設會開啟前鏡頭，如果你讓使用者使用前鏡頭去掃QRCode，體驗上很怪不說，使用者應該會很想揍你。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cQcG8eKXo-iqEOM6SDR9dw.png" /></figure><p>下一步，引入 WebAssembly套件，這部分 React(CRA) 的環境上是<strong>完全不需要</strong>額外設定任何東西的。直接安裝 WebAssembly 套件並 Import 即可。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ej6EHDoqpN16S6ZKIUg2pg.png" /><figcaption>直接import</figcaption></figure><p>接下來把接上 <a href="https://developer.mozilla.org/en-US/docs/Web/API/Media_Streams_API">MediaStreams</a> 串流的 Video Element 抓過來並利用 requestAnimationFrame 把每一幀 Render 進 Canvas 裡面，再把每一幀送給wasm 的影像處理函式。<br>這個函式會返回一個陣列，如果有偵測到 Qrcode 的話，會把相關資訊塞進這個返回的陣列中。我們就可以拿著這個陣列中的資訊來額外做一些處理，舉個例子這邊就是直接在偵測到 QRCode 的四個角落畫上圓圈標記。</p><p>上述這些操作經過實測都能保持在 25~50FPS 左右，算是相當的流暢。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sr6QFhIfunrldpsoMZKJNw.png" /></figure><p>另外如果是由 Vue CLI 生成的專案裡面想要使用這個套件的話，需要額外對Webpack 做一點設定，我跟同事 Simon 在這個部分稍微卡了一陣子。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*33B4uoDLTNheySgvSOT5dw.png" /><figcaption>Vue CLI生成專案要使用 WASM 套件的 Webpack 額外設定</figcaption></figure><h3>結語</h3><p>這次有機會接觸並研究這個前端領域的前沿技術，覺得玩起來還蠻有趣的。另外也更期待 WebAssembly 這個技術未來的發展。</p><p>另外我覺得漸強在文化上，其實蠻鼓勵大家去學習新知識，也沒什麼技術包袱。只要經過團隊內部討論過，就可以將這些技術直接用在工作中。<br>另外在前端工程師的 <a href="https://roadmap.sh/frontend">Skill Tree</a> 中，可以看到 WebAssembly 其實是在整個技能樹的相當末端 XD，以目前來說算是真的相對前沿的技術。<br>累積這些新知與保持對新事物的敏感度，對工程師來說是百利而無一害。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c-ab76xWMMcDdga-bcE8Yw.png" /></figure><p>我們後續會繼續深入研究 WebAssembly 並記錄下來。下一篇我們打算利用 C/C++/Rust 來自己撰寫程式碼並編譯成 WebAssembly。<br>雖然這次沒有做到 WebAssembly 跟 JS 的效能對比，不過目前查到的資訊效能大概可以差到 3~10 倍，關於這方面的對比，之後的文章會再做深入的研究比較。</p><h3>WebAssembly 相關資料蒐集與可玩清單</h3><p>這邊我們有蒐集相關的套件與資訊 大家可以參考一下</p><p><a href="https://tech.ebayinc.com/engineering/webassembly-at-ebay-a-real-world-use-case/">https://tech.ebayinc.com/engineering/webassembly-at-ebay-a-real-world-use-case/</a></p><p><a href="https://www.figma.com/blog/webassembly-cut-figmas-load-time-by-3x/">https://www.figma.com/blog/webassembly-cut-figmas-load-time-by-3x/</a></p><p><a href="https://github.com/samsam2310/zbar.wasm">https://github.com/samsam2310/zbar.wasm</a></p><p>最後感謝跟我一起研究並且也是這篇文章的共筆者，Simon。</p><p>然後在這邊業配一下，漸強實驗室前後端工程師募集中<br>相關職缺請上：<a href="https://www.yourator.co/companies/CrescendoLab">https://www.yourator.co/companies/CrescendoLab</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e52d8a286d6d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/%E6%BC%B8%E5%BC%B7%E5%AF%A6%E9%A9%97%E5%AE%A4-crescendo-lab-engineering-blog/webassembly%E6%AF%94%E6%83%B3%E5%83%8F%E7%9A%84%E9%9B%A2%E4%BD%A0%E9%82%84%E8%BF%91-%E4%B9%8B%E5%89%8D%E7%AB%AFqrcode%E6%8E%83%E6%8F%8F-e52d8a286d6d">WebAssembly比想像的離你還近 — 之前端QRCode掃描</a> was originally published in <a href="https://medium.com/%E6%BC%B8%E5%BC%B7%E5%AF%A6%E9%A9%97%E5%AE%A4-crescendo-lab-engineering-blog">漸強實驗室 Crescendo lab — 職涯部落格 Career blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript 基本認識]]></title>
            <link>https://vibrissa-yang.medium.com/javascript-%E5%9F%BA%E6%9C%AC%E8%AA%8D%E8%AD%98-3c846e77353a?source=rss-604820524055------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c846e77353a</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[楊詠翔(Vibrissa)]]></dc:creator>
            <pubDate>Mon, 21 May 2018 05:54:42 GMT</pubDate>
            <atom:updated>2018-05-21T05:54:42.256Z</atom:updated>
            <content:encoded><![CDATA[<h3>基本型別</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Glossary/Boolean">Boolean</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Glossary/Null">Null</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Glossary/Undefined">Undefined</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">Number</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Glossary/String">String</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Glossary/Symbol">Symbol</a></li></ul><h3>動態型別</h3><p>JavaScript 是弱型別，也能說是動態的程式語言。這代表你不必特別宣告變數的型別。程式在運作時，型別會自動轉換。這也代表你可以以不同的型別使用同一個變數。</p><h3>Object 的 Name Value Pair</h3><pre>var box= {<br>  size:16,<br>  color:&#39;red&#39;,<br>  child_box:{<br>    size:5,<br>    color:&#39;blue&#39;<br>  }<br>}</pre><pre>var a = 1;<br>var b = a;</pre><pre>b = 3;<br>console.log(a);</pre><pre>// object<br>var a = {name: &#39;Eric&#39;};<br>var b = a;<br>b.name = &#39;Joesph&#39;;<br>console.log(a); </pre><pre>//---------------------------------------------------//</pre><pre>let a = { <br>  b:{<br>    c:1<br>  },<br>  d:{<br>    e:{<br>      f:7<br>    }<br>  },<br>  z:&#39;yoyo!&#39;<br>}</pre><pre>let g = Object.assign( {},a );</pre><pre>let h = JSON.parse(Json.stringify(a));</pre><h3>運算子Operator</h3><pre>var box = 1 + 2 ;<br>var box2 = 1 + &#39;2&#39;;</pre><h3>為什麼Javascript的相等判斷要用’===’而不是’==’</h3><pre>console.log( 1 == 1 );<br>console.log( 1 == &#39;1&#39; );<br>console.log( 1 == true );</pre><h3>Javascript Function 是 First Class Fucnction</h3><pre>function add ( a, b ) {<br>  retutn a + b; <br>}<br> <br>add(1,2);</pre><pre>//---------------------------------------------------//</pre><pre>var addType2 = function( a , b ) { <br>  return a + b <br>}<br>addType2(1,2);</pre><pre>//---------------------------------------------------//</pre><pre>var excuteWhatYouPut = function( WhatYouPut ) { <br>  WhatYouPut();<br>};<br>var logText = function (){ <br>  console.log(&#39;yoyo!&#39;);<br>};<br>logText.mermer = &#39;xxx&#39;;</pre><pre>logText();</pre><pre>excuteWhatYouPut(logText);</pre><pre>console.log(logText.mermer);</pre><h3>Function的Hoisting 與變數的undefined</h3><pre>console.log( text );</pre><pre>var text = &#39;yoyo!&#39;;</pre><pre>console.log( text );</pre><pre>//---------------------------------------------------//</pre><pre>a();</pre><pre>function a(){ <br>  console.log(&#39;i am function a!&#39;);<br>}</pre><pre>a();</pre><pre>//---------------------------------------------------//</pre><pre>b();</pre><pre>var b = function(){ <br>  console.log(&#39;i am function b!&#39;);<br>}</pre><pre>b();</pre><pre>//---------------------------------------------------//</pre><h3>lexical Environment</h3><pre>var textbox = &#39;yoyo&#39;;</pre><pre>function log () { <br>  var textbox = &#39;左左&#39;;<br>  console.log(textbox);  <br>}</pre><pre>console.log(textbox);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c846e77353a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript 的運作原理與基礎(1) Execution Contexts]]></title>
            <link>https://vibrissa-yang.medium.com/javascript-%E7%9A%84%E9%81%8B%E4%BD%9C%E5%8E%9F%E7%90%86%E8%88%87%E5%9F%BA%E7%A4%8E-1-execution-contexts-6631d9531f82?source=rss-604820524055------2</link>
            <guid isPermaLink="false">https://medium.com/p/6631d9531f82</guid>
            <dc:creator><![CDATA[楊詠翔(Vibrissa)]]></dc:creator>
            <pubDate>Fri, 30 Mar 2018 08:22:26 GMT</pubDate>
            <atom:updated>2018-03-30T08:22:26.865Z</atom:updated>
            <content:encoded><![CDATA[<p>這系列文章的由來是這樣</p><p>其實接觸Javascript也一陣子了，從最早接觸的<strong>Jquery</strong> 到最近的<strong> Vue.js</strong> 和 <strong>React Styled Component</strong> 等等….</p><p>當然除了上述的套件跟框架類<strong>js</strong>我也在網頁上寫過很多原生的js 程式碼，但是我最近因為要開發一個套件類的<strong>js</strong>讓我開始感覺的我基礎<strong>js</strong>認識的不足，讓我開始整理這篇文章，另外我很久之前再Udemy上買的一門Javascript課也還沒上完，所以這篇文章是整理上課的內容加上搜集資料整理而成。</p><h3>Syntax Parser 語法解析器</h3><blockquote>簡單來說語法解析器會讀入你寫的程式 然後把你的程式切成一個個最小單位的Token並建成語法樹，判斷語法有沒有錯誤，接著翻譯成電腦看得懂的二元碼並且執行程式。(這是最簡略的解釋了，這邊不多作著墨)</blockquote><h3>Execution Contexts 執行環境</h3><blockquote>執行環境是一種包住你正在執程式的外層，很好，Hen抽象。執行環境跟Jasvascript的<strong>this</strong>有很大的關係，下面會用實例做解釋</blockquote><p>首先我們來看一段簡單的程式碼</p><pre>function Apple(){ <br>  var what_apple_say = &#39;I am apple&#39;;<br>  Yo();<br>  console.log(what_apple_say);<br>}</pre><pre>function Yo(){<br>  console.log(&#39;yo!&#39;)<br>}</pre><pre><br>Apple();<br>console.log(&#39;all done&#39;);</pre><p>根據上面這段程式碼，我們來解釋一下javascript如何運作，並且解釋一下Execution Context ，首先在初始化這段程式的時後會產生一個Global的 Execution Context，把所有的變數跟 function assign 進瀏覽器的window變數裡面 並且產生一個this</p><pre>|                   |<br>|       Global      |<br>|______________this_|</pre><p>初始化完成後，開始執行階段這時候Apple()會被執行接著產生了一個新的Execution Context，並建立自己的變數(what_apple_say)然後產生一個this。<br>而這個Execution Context 是疊在Global上面的，他是一個Stack的資料結構。</p><pre>|                   |<br>|       Apple       |<br>|______________this_|<br>|                   |<br>|       Global      |<br>|______________this_|</pre><p>這時候Apple這個function裡面又呼叫了Yo()<br>又產生了一個新的Execution Context，並建立自己的變數(這裡沒有變數)然後產生一個this。</p><pre>|                   |<br>|        Yo         |<br>|______________this_|<br>|                   |<br>|       Apple       | <br>|______________this_|<br>|                   |<br>|       Global      |<br>|______________this_|</pre><p>每個Execution Context執行完成後會發生什麼事？<br>他們會一個一個被push出這個stack，依照這邊的例子Yo的Execution Context會最先被丟掉，接下來是Apple，接下來是Glabal。</p><p>隨著Global被丟掉，也代表這段程式執行完畢了(暫時沒有新的code可以跑了)。關於Execution Context的運作到這邊應該大概有一個概念了。至於this是什麼他每次被建立又會指向誰等等之類的細節，可能要另外寫一篇文章來解釋了。</p><h3>Lexical Environments 詞彙環境</h3><blockquote>這個叫做詞彙環境的玩意還蠻特別的，簡單來說它就是一種<br>你的程式所在的位置和你程式的周圍是什麼的概念。我知道聽起來超級抽像的，等等會有實例來解釋一下。</blockquote><p>這個留到下一篇文章解釋，這玩意其實會影響多個同樣命稱的變數你到底會用到哪一個變數。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6631d9531f82" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>