<?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 Roi Lin on Medium]]></title>
        <description><![CDATA[Stories by Roi Lin on Medium]]></description>
        <link>https://medium.com/@fabien705cccc?source=rss-1ea35533de43------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Cvm4ZAkfEwAwO2YU</url>
            <title>Stories by Roi Lin on Medium</title>
            <link>https://medium.com/@fabien705cccc?source=rss-1ea35533de43------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 19:59:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fabien705cccc/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[[Javascript]   ===  vs.  ==]]></title>
            <link>https://medium.com/@fabien705cccc/javascript-vs-3f6397366022?source=rss-1ea35533de43------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f6397366022</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Roi Lin]]></dc:creator>
            <pubDate>Fri, 27 Sep 2019 08:32:35 GMT</pubDate>
            <atom:updated>2019-09-27T09:10:10.961Z</atom:updated>
            <content:encoded><![CDATA[<h3>[Javascript] === vs. ==</h3><p>最近看了一些CODE 發現大家在寫js判斷時都會寫&quot;===&quot;，而不是&quot;==&quot;，所以查了一下這兩者的差別。</p><h3>比較運算式</h3><p>&quot;==&quot; ：較不嚴謹，只比較&quot;值&quot;。比較時會先進行型別的轉換，再比較裡面的值。</p><p>&quot;===&quot;：較嚴謹，會比較&quot;型別&quot;與&quot;值&quot;。</p><p>會先比較&quot;型別&quot;，如果不相符就會回傳false，不比較&quot;值&quot;</p><h4>一般變數</h4><p>以下面這個例子來說，使用&quot;==&quot;進行比較時會先將num與str轉換成一致的型態，因此，比較時會是一致的</p><pre>// 基本型別 (ex. int string)<br>var num = 3;<br>var str = &#39;3&#39;;<br>console.log(num == str); <br>//return true<br>console.log(num === str);<br>//return false</pre><p>不過這時，如果是boolean時，&#39;true&#39;與true 會是不相等的</p><pre>var isOK = true;<br>var result = &#39;true&#39;;<br>console.log(isOK == result); <br>//return false<br>console.log(isOK === result);<br>//return false</pre><p>true會轉成 &#39;1&#39;</p><pre>//Boolean test2<br>var isOK = true;<br>var result = &#39;1&#39;;<br>console.log(isOK == result); <br>//return false<br>console.log(isOK === result);<br>//return false</pre><h4>Null &amp; undefined 的比較</h4><pre>// Null &amp; undefined <br>var test;<br>var test2 = null;<br>console.log(test == test2);<br>//return true<br>console.log(test === test2);<br>//return false</pre><h4>物件</h4><p>當比較的型別為&quot;Object&quot;時，是比較是否指向同一個記憶體位置。</p><p>為什麼是比較記憶體位置呢？這就牽扯到<a href="https://ithelp.ithome.com.tw/articles/10209104">JS 中Pass by value, or Pass by reference</a>，裡面描述當變數的值是原生型別 (Primitive) 時，行為是 Pass by value，原生型別包含：</p><ol><li>String</li><li>Number</li><li>Boolean</li><li>Undefined</li><li>Null</li></ol><p>當變數的值是物件型別 (Object) 時，行為是 Pass by reference<br>在 JavaScript 中的物件型別常見的例如：</p><ol><li>Array</li><li>Object</li></ol><p>當兩個物件指向不同位址時，等式不會成立</p><pre>var objA = {&#39;name&#39;:&#39;roi&#39;};<br>var objB = {&#39;name&#39;:&#39;roi&#39;};<br>console.log(objA == objB); <br>//return false<br>console.log(objA === objB);<br>//return false<br>console.log(objA == {&#39;name&#39;:&#39;roi&#39;}); <br>//return false</pre><p>當兩個物件指向同個位址時，等式會成立</p><pre>var objA = {&#39;name&#39;:&#39;roi&#39;};<br>var objB = objA;<br>console.log(objA == objB); <br>//return true<br>console.log(objA === objB);<br>//return true</pre><p>上面的code，可以改改這邊的code <a href="https://codepen.io/sinyilin/pen/jONvBYB">https://codepen.io/sinyilin/pen/jONvBYB</a> 來觀察改變。</p><h3>總結</h3><p>到底要用&quot;==&quot; 還是&quot;===&quot;呢？</p><p>以Null &amp; undefined為例，當你的result 進行了一連串的運算，但中間出了錯誤導致回傳undefined而不是null。但如果你要拿這個判斷來執行後續的行為的話就可能會產生錯誤。</p><pre>var result = undefined;</pre><pre>if(result == null){<br>    console.log(&quot;相符1&quot;); //會输出<br>}<br>if(result === null){<br>    console.log(&quot;相符2&quot;); //不會输出<br>}</pre><p>為了避免發生類似這樣的錯誤，建議盡量使用嚴謹的”===”進行比較。</p><h3>參考資料：</h3><ol><li>[Javascript] 等於的運用 — ==和 ===的不同之處<a href="https://dotblogs.com.tw/alantsai/2013/06/27/106134">https://dotblogs.com.tw/alantsai/2013/06/27/106134</a></li><li>JS/JavaScript中两个等号 == 和 三个等号 === 的区别<a href="https://blog.csdn.net/chenchunlin526/article/details/78850171">https://blog.csdn.net/chenchunlin526/article/details/78850171</a></li><li>你不可不知的 JavaScript 二三事#Day26：程式界的哈姆雷特 — — Pass by value, or Pass by reference？<a href="https://ithelp.ithome.com.tw/articles/10209104">https://ithelp.ithome.com.tw/articles/10209104</a></li><li>Null &amp; undefined 型態差 <a href="https://ithelp.ithome.com.tw/articles/10103799">https://ithelp.ithome.com.tw/articles/10103799</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f6397366022" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue 中如何控制class與style?]]></title>
            <link>https://medium.com/@fabien705cccc/vue-%E4%B8%AD%E5%A6%82%E4%BD%95%E6%8E%A7%E5%88%B6class%E8%88%87style-a595f6cb9c39?source=rss-1ea35533de43------2</link>
            <guid isPermaLink="false">https://medium.com/p/a595f6cb9c39</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Roi Lin]]></dc:creator>
            <pubDate>Sun, 01 Sep 2019 14:29:16 GMT</pubDate>
            <atom:updated>2019-10-17T09:13:25.029Z</atom:updated>
            <content:encoded><![CDATA[<h3>Vue 中如何使用 class與style?</h3><p>在Vue中是透過v-bind來控制class與style的呈現，如下：</p><pre><strong>v-bind:class=&quot;xxx&quot; </strong>或 <strong>v-bind:style=&quot;xxx&quot;<br>也可以簡寫為:class=&quot;xxx&quot; 或 :style=&quot;xxx&quot;</strong></pre><h4><strong>程式範例</strong></h4><p><a href="https://codepen.io/sinyilin/pen/gOYxEYo">https://codepen.io/sinyilin/pen/gOYxEYo</a></p><pre># Vue Instance<br>var vm = new Vue({<br>      el: &#39;#app&#39;,<br>      data: {<br>        //class<br>        isBlue: true,<br>        largeFont: &#39;big-size&#39;,<br>        pinkBackground: &#39;pink-bg&#39;,<br>        //style<br>        activeColor: &#39;red&#39;,<br>        fontSize: 30,<br>        styleObject1: {<br>          color: &#39;green&#39;,<br>          fontSize: &#39;20px&#39;,<br>          marginBottom: &#39;10px&#39;<br>        },<br>        styleObject2: {<br>          backgroundColor: &#39;cyan&#39;,<br>          lineHeight: &#39;2em&#39;<br>        }<br>      }<br>    });</pre><h4>Class</h4><p>以class有幾種呈現方式：</p><p>第一種：{className : 判斷式或boolean變數(可以從vue instance取得)}</p><pre>&lt;div :class=&quot;{ blue: isBlue }&quot;&gt;&lt;/div&gt;</pre><p>以這個例子來說，前面的blue為class名稱，當後面的判斷式或變數為true時則替該標籤加入blue的class。</p><p>第二種：使用單一vue instance的變數</p><pre>&lt;div :class=&quot;largeFont&quot;&gt;2 Hello Vue!&lt;/div&gt;</pre><p>因此，結果呈現時會class=“big-size”。</p><p>第三種：使用陣列的方式帶入多個vue instance變數</p><pre>&lt;div :class=&quot;[largeFont, pinkBackground]&quot;&gt;&lt;/div&gt;</pre><p>因此，結果呈現時會class=“ big-size pink-bg” 兩個。</p><h4><strong>Style</strong></h4><pre>:style=&quot;{&#39;屬性樣式&#39;:&#39;樣式的值&#39;}&quot;</pre><p>第一種：使用單一vue instance的變數</p><pre>&lt;div :style=&quot;{ color: activeColor, fontSize: fontSize + &#39;px&#39; }&quot;&gt;&lt;/div&gt;</pre><p>第二種：利用單一物件</p><pre>&lt;div :style=&quot;styleObject1&quot;&gt;&lt;/div&gt;</pre><p>第三種：</p><pre>&lt;div :style=&quot;[styleObject1, styleObject2]&quot;&gt;&lt;/div&gt;</pre><p>這邊有一個特別需要注意的地方，以style第三種的例子為順序來說，假設當styleObject1與styleObject2擁有相同屬性，也就是styleObject1有color:red，styleObject2有color:blue，後寫的屬性會蓋過先寫得的屬性。</p><h4><strong>使用注意事項</strong></h4><p>最後，在使用:class 與:style，需要特別注意一件事。</p><p>當物件的key 有-時的處理方式，例如backgroung-color。</p><pre># 方法一：會改為駝峰式來作為key值。<br>&lt;div class=&#39;box&#39; :style=&quot;{backgroundColor: &#39;red&#39;}&quot;&gt;&lt;/div&gt;</pre><pre># 方法二：將key加上&#39;&#39;<br>&lt;div class=”box” :style=”{‘background-color’: ‘red’}”&gt;&lt;/div&gt;</pre><p>原則上object的key 是不能允許有 -，但如果真的要使用，可以改為下面這樣寫，在該key以及取值的地方加上&quot;&quot;。</p><pre>objectClass: {<br> &#39;rotate&#39;: false,<br> &#39;bg-danger&#39;: false,<br> },</pre><pre># 需要這樣呈現<br>v-model=&quot;objectClass[&#39;bg-danger&#39;]&quot;</pre><h3><strong>結論</strong></h3><p>使用:class與:style可能也還有其他種用法，上面是我列出我目前知道的用法，如果有其他種用法的也歡迎告訴我。</p><h4>補充範例</h4><p>當結果是true時，顯示A class，結果是false時，顯示B class。</p><p>可以參考這篇<a href="http://yaohuitao.com/?p=379">文章</a></p><p>以上是我的學習筆記，如果有錯誤的話也歡迎在下方留言告知我，謝謝～</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a595f6cb9c39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue 的生命週期(Lifecycle)]]></title>
            <link>https://medium.com/@fabien705cccc/vue-%E7%9A%84%E7%94%9F%E5%91%BD%E9%80%B1%E6%9C%9F-lifecycle-3522c481e63f?source=rss-1ea35533de43------2</link>
            <guid isPermaLink="false">https://medium.com/p/3522c481e63f</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[lifecycle]]></category>
            <dc:creator><![CDATA[Roi Lin]]></dc:creator>
            <pubDate>Tue, 27 Aug 2019 15:24:34 GMT</pubDate>
            <atom:updated>2019-09-04T06:54:16.457Z</atom:updated>
            <content:encoded><![CDATA[<p>最近開始接觸Vue，趁著記憶還很新的時候記錄一下我所記得的內容。</p><p>Vue的生命週期就是Vue的實體(Instance)到從建立-&gt;更新-&gt;摧毀的這段過程。</p><p>官方在這段過程中提供一些方法( Hook function)給開發者進行使用，如下圖中的紅色方框。</p><p>當我們生命週期到某一個點的時候就會觸發這個Hook function，因此可以在特定的時間點對Vue實體進行操作。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ys7vir6PTVK-d8us.png" /></figure><p>以下是我對Vue生命週期的解釋</p><h3><strong>Vue 生命週期</strong></h3><p>以下我利用<strong>粗體字 Highlight Hook function :</strong></p><ol><li>new Vue() :建立Vue的實體</li><li><strong>beforeCreate : 尚未初始化前，無法取得vue 實體裡的 vm.$data，也不會生成DOM元素。</strong></li><li>Observe Data &amp; Init Events： 開始初始化。</li><li><strong>Created：實體已經建立，屬性已綁定，因此在此才能拿到 vue 實體裡的 vm.$data，不過DOM元素還沒有生成。</strong></li><li>判斷實體裡面的$.el是否有被掛載，如果沒有的話後續就都不會執行直到vm.$mount()被呼叫；有的話會繼續往下執行。</li><li>判斷實體內是否有template 屬性，有的話就使用template 的內容當作樣板之後用來render 畫面；沒有的話就使用綁定el的html當作樣板之後用來render 畫面。</li><li><strong>beforeMount：模板 (template) 編譯並掛載至 HTML 之前，此時template中被綁定的元素還尚未轉換為要輸出的HTML，例如還是{{count }}。</strong></li><li>模板(<strong>template</strong>)編譯與掛載。</li><li><strong>mounted：模板 (template) 編譯並掛載至 HTML 之後，此時template中被綁定的元素已轉換為要輸出的HTML，例如0。此時就好像JQuery中的ready()。</strong></li><li><strong>beforeUpdate：更新前，在這邊可以取得更新前與後的資料。</strong></li><li>Create $.el ….and replace el ：render 畫面。</li><li><strong>updated：更新後。</strong></li><li><strong>activated：有使用&lt;keep-alive&gt;&lt;/keep-alive&gt;才會用到</strong>。</li><li><strong>deactivated：有使用&lt;keep-alive&gt;&lt;/keep-alive&gt;才會用到</strong>。</li><li><strong>beforeDestroy：實體被摧毀前。</strong></li><li><strong>destroyed：實體摧毀，監聽事件、子實體會被銷毀。</strong></li></ol><h4>範例程式</h4><p>這邊有一段 沒有使用&lt;keep-alive&gt;&lt;/keep-alive&gt; 的 <a href="https://codepen.io/sinyilin/pen/xxKqYGO">code</a> 可以幫助理解，可以透過console來觀看生命週期。</p><p>一開始console如下：</p><pre>&quot;beforeCreate - this.count: &quot; undefined</pre><pre>&quot;beforeCreate - this.$el: &quot; undefined</pre><pre>&quot;created - this.count: &quot; 0</pre><pre>&quot;created - this.$el: &quot; undefined</pre><pre>&quot;beforeMount - this.$el: &quot; &quot;&lt;div id=&#39;app&#39;&gt;<br>&lt;h1&gt; {{ count }}&lt;/h1&gt;<br>&lt;button class=&#39;btn btn-primary&#39; @click=&#39;add&#39;&gt;Count&lt;/button&gt;<br>&lt;/div&gt;&quot;</pre><pre>&quot;mounted - this.$el: &quot; &quot;&lt;div id=&#39;app&#39;&gt;&lt;h1&gt; 0&lt;/h1&gt; &lt;button class=&#39;btn btn-primary&#39;&gt;Count&lt;/button&gt;&lt;/div&gt;&quot;</pre><ol><li>可以看到beforeCreate階段時，因為還沒init，所以data 跟 el 都取不到。</li><li>created時 可以取到data 但還沒確認el。</li><li>beforeMount時可以取得模板。</li><li>mounted時取得模板並綁定屬性。</li></ol><p>更新時的console:</p><p>第一個數字為畫面上的html取得的，第二個數字為this.count</p><p>這時你就會有一個疑惑為什麼在beforeUpdate時的this.count 不是0，而是1。</p><p>因為這邊的this.count已經是觸發更新後的數字，只是尚未呈現在畫面上。</p><pre>&quot;beforeUpdate: &quot; &quot;0&quot; 1</pre><pre>&quot;updated: &quot; &quot;1&quot; 1</pre><p>在練習這個範例時除了遇到beforeUpdate時的疑問外，還有幾個需要注意的點：</p><ol><li>如果vue 實體中沒有綁定el 的話，beforeMount以後的hook function都不能使用。</li><li>destroyed是銷毀監聽方法、子元素、data，但html要自己手動清除。</li><li>destroyed要記得寫在el綁定的元素外面，不然摧毀事件會被刪除。</li></ol><h4><strong>&lt;keep-alive&gt;&lt;/keep-alive&gt;</strong></h4><p>用途：舉個例子做頁籤時或填寫表單時還是希望保留狀態。保留資料狀態不將實體destroyed。使用該標籤時不會進入beforeDestroy與destroyed，而是變成activated與deactivated。</p><h3>總結</h3><p>在最最最一開始學Vue的時候可能不太會用到，不過了解Vue實體的生命週期可以讓你在對的階段做對的事。</p><p>舉個例子，像是透過ajax取得資料時應該要寫實體建立階段的created 之後， 也就是created、beforeMount 與 mounted。建議放created，不建議在mounted 因為網頁畫面可能會有一段空白，但可以用loading 圖蓋過。</p><p>以上如果有錯誤的話也歡迎在下方留言告知我，謝謝～</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3522c481e63f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mac ＆ Win7 port 佔用處理方式]]></title>
            <link>https://medium.com/@fabien705cccc/mac-win7-port-%E4%BD%94%E7%94%A8%E8%99%95%E7%90%86%E6%96%B9%E5%BC%8F-76387543b402?source=rss-1ea35533de43------2</link>
            <guid isPermaLink="false">https://medium.com/p/76387543b402</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[command-line]]></category>
            <dc:creator><![CDATA[Roi Lin]]></dc:creator>
            <pubDate>Sat, 24 Aug 2019 14:24:18 GMT</pubDate>
            <atom:updated>2019-09-03T09:21:44.325Z</atom:updated>
            <content:encoded><![CDATA[<p>spring boot 運作時會佔用掉一個port ，若無良好關閉，會導致程式無法在該port執行。</p><p>因為我太容易忘記了，所以在這邊做一點紀錄。</p><h4><strong>[Mac OX]</strong></h4><p>會因為osx版本不一樣會有不同做法，我目前電腦的版本是10.13</p><p>1.列出佔用該port的process</p><pre>#範本lsof -i tcp:{port num}<br>lsof -i tcp:7006</pre><p>2.取得PID，刪除該process</p><pre>#範本 kill -9 {pId}<br>kill -9 12334</pre><p><strong>參考文章</strong></p><p><a href="http://blog.it4fun.net/archives/162">http://blog.it4fun.net/archives/162</a></p><h4><strong>[Windows7]</strong></h4><ol><li>列出佔用該port的process，LISTENING後的的數字為PID。</li></ol><pre>#範本 netstat -nao |find &quot;0.0.0.0:{port num}&quot;<br>netstat -nao |find &quot;0.0.0.0:7006&quot;</pre><p>2.找出該process是什麼，也可忽略這個步驟，因為上面已經取的PID</p><pre>#範本 tasklist /fi &quot;pid eq 4116&quot;<br>tasklist /fi &quot;pid eq 4116&quot;</pre><p>3.刪除佔用該port的process</p><pre>#範本 taskkill /pid {pid num} /F<br>taskkill /pid 4116 /F</pre><p>參考文章</p><p><a href="http://herolin.twbbs.org/entry/how-to-check-port-which-used-program-for-windows-and-linux/">http://herolin.twbbs.org/entry/how-to-check-port-which-used-program-for-windows-and-linux/</a></p><p>以上如果有錯誤的話也歡迎在下方留言告知我，謝謝～</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76387543b402" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>