<?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 Osaki Hsieh on Medium]]></title>
        <description><![CDATA[Stories by Osaki Hsieh on Medium]]></description>
        <link>https://medium.com/@aspdoctor?source=rss-fe2ca1cb407------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aAcE5ICnRVo1emuBXOdOKA.jpeg</url>
            <title>Stories by Osaki Hsieh on Medium</title>
            <link>https://medium.com/@aspdoctor?source=rss-fe2ca1cb407------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:49:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aspdoctor/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[Vue 的嫑嫑的 Vue-cli ( 1 )]]></title>
            <link>https://medium.com/osakihsieh/vue-%E7%9A%84%E5%AB%91%E5%AB%91%E7%9A%84-vue-cli-%E3%84%A7-f7a5fca79e40?source=rss-fe2ca1cb407------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7a5fca79e40</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[vue-cli]]></category>
            <dc:creator><![CDATA[Osaki Hsieh]]></dc:creator>
            <pubDate>Tue, 21 Mar 2017 18:17:50 GMT</pubDate>
            <atom:updated>2017-03-22T15:08:13.404Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TTiR9OhOSgw-2-ZzAe4_Jw.jpeg" /><figcaption>教練，我想趕快開始寫程式阿</figcaption></figure><p><a href="https://vue-cli-7110b.firebaseapp.com/landing">Vue-Cli from scratch | Osaki Hsieh</a></p><p>時至今日，前端開發的複雜跟過去已不可同日而語<br>為了開始一個新專案，需要拉一堆有的沒的的庫、拉一堆大的小的依賴包，<br>拉了庫、拉了依賴，還需要弄個 <em>Development Server</em> 方便開發，</p><p>好不容易佈好開發環境，半天就過去了，<br>主管關心今天進度如何的時候，只能面帶尷尬的看著螢幕上白白一片的 <em>&#39;Hello World!&#39;</em> 準備加班，像個十足的魯蛇</p><p>想不加班，就得簡化自己的工作流程，<br>這類重複性質高的瑣事，就該交給電腦自動化處理</p><p>所以我們需要用 <a href="http://yeoman.io/"><em>Yeoman</em></a><em> </em>之類的工具，<br>幫忙對 <a href="http://gulpjs.com/"><em>gulp</em></a>、<a href="https://webpack.js.org/"><em>webpack</em></a><em> </em>等工具做些開發前的設定，<br>既然都用了 <a href="https://vuejs.org/"><em>Vue.js</em></a> 作為主要的庫了，<br>那官方提供的 <a href="https://github.com/vuejs/vue-cli"><em>Vue-cli</em></a> 肯定是建構工具的首選</p><h4>Installation</h4><p>首先，我們開啟終端機，先在開發的電腦上安裝 <em>Vue-cli</em></p><pre>$ npm install -g vue-cli</pre><h4>Commands</h4><p>接著輸入 vue 來看看 <em>Vue-cli</em> 裡的幾個命令<br><em>Vue-cli</em> 一共只有四個命令，看到這裡，<br>大致上已經可以直接開始做開發了</p><pre><em>// 初始化一個 Vue 專案</em><br>$ vue init [template-name] [project-name]</pre><pre><em>// 官方 Vue Template 列表</em><br>$ vue list</pre><pre><em>// 測試 .vue 單檔</em><br>$ vue build [entry]</pre><pre><em>// 恩..對，就是幫助訊息</em><br>$ vue help [cmd]</pre><h4>Templates</h4><p>輸入 vue list 可以看到官方提供的幾個 <em>Vue.js</em> 建構樣板<br>如果沒什麼想法的話，推薦使用 <a href="https://github.com/vuejs-templates/webpack"><strong><em>webpack</em></strong></a><strong><em> </em></strong>這個樣板，他有比較完整的轉譯、代碼審查、建構及測試工具</p><ul><li><strong>simple</strong><br>index.html + Vue CDN import</li><li><strong>webpack-simple</strong><br>基本的 Webpack + vue-loader 開發流程</li><li><strong>webpack </strong><br>完整的 Webpack + vue-loader 開發流程，包含linting、測試工具</li><li><strong>browserify</strong><br>完整的 Browserify + vueify 開發流程，包含linting、測試工具</li></ul><h4>Init</h4><p>最後我們來初始化一個新的 <em>Vue </em>專案，<br>以上個區塊推薦的 <em>webpack </em>樣板為例，</p><pre>$ vue init <strong>webpack</strong> <strong>my-vue-project<br></strong>$ cd my-vue-project &amp;&amp; npm install &amp;&amp; npm run dev</pre><p>原本複雜的工作流程，現在簡化成只需要這樣兩行搞定，<br>馬上就得到一個原本需要半天時間才出現的<em> &#39;Hello World!&#39;</em><br>馬上就可以開始真正的開發作業，<br>馬上就晉升<strong>高級工程師<br></strong>馬上考試都一百分</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*fFef13QoqZOQEax-cpe6kw.jpeg" /></figure><p>另外的 vue build 到底是什麼鬼東西，能幹嘛 ?<br>還有怎麼建構、使用自己寫的 vue-template ?<br>就留到下一篇啦，掰噗</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7a5fca79e40" width="1" height="1" alt=""><hr><p><a href="https://medium.com/osakihsieh/vue-%E7%9A%84%E5%AB%91%E5%AB%91%E7%9A%84-vue-cli-%E3%84%A7-f7a5fca79e40">Vue 的嫑嫑的 Vue-cli ( 1 )</a> was originally published in <a href="https://medium.com/osakihsieh">前端急制</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[滿滿的大 ES6 - Destructuring]]></title>
            <link>https://medium.com/osakihsieh/%E6%BB%BF%E6%BB%BF%E7%9A%84%E5%A4%A7-es6-destructuring-264d2b6b2f5f?source=rss-fe2ca1cb407------2</link>
            <guid isPermaLink="false">https://medium.com/p/264d2b6b2f5f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[destructuring]]></category>
            <dc:creator><![CDATA[Osaki Hsieh]]></dc:creator>
            <pubDate>Tue, 21 Feb 2017 20:04:51 GMT</pubDate>
            <atom:updated>2017-02-22T11:41:51.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*BAeYTJvO7IdZC4rH03puQg.jpeg" /></figure><p>身為一個優雅的工程師，你當然需要優雅地處理數組!<br>現在才談已經不夠潮的 <strong>ES6</strong> ，絕大部分的新工具都是針對數組的處理<br>其中翻成中文更看不懂的 <strong>Destructuring </strong>(解構)，更是替滿身汗臭的臭宅工程師蛻變成<a href="https://i.ytimg.com/vi/iVFOW2-3zsk/sddefault.jpg"><strong>某個角度像金城武</strong></a>的優雅型男的必備良藥。</p><p>先來簡單看看 Destructuring 的模樣</p><pre>// EX. 1<br>const [a, b] = [&#39;a&#39;, &#39;b&#39;]<br>console.log(a) // &#39;a&#39;<br>console.log(b) // &#39;b&#39;</pre><pre>// EX. 2<br>const [a, b, ...rest] = [1, 2, 3, 4, 5]<br>console.log(a) // 1<br>console.log(b) // 2<br>console.log(rest); // [3, 4, 5]</pre><pre>// EX. 3<br>const {a, b} = {a: 1, b: 2}<br>console.log(a) // 1<br>console.log(b) // 2</pre><p>沒那麼帥氣? 那再來看看它整型前的樣子</p><pre>// EX. 1<br>var origin = [&#39;a&#39;, &#39;b&#39;];<br>var a, b;<br>a = origin[0];<br>b = origin[1];<br>console.log(a); // &#39;a&#39;<br>console.log(b); // &#39;b&#39;</pre><pre>// EX. 2<br>// 這個範例太麻煩了懶得寫</pre><pre>// EX. 3<br>var origin = {a: 1, b: 2}<br>var a, b<br>a = origin.a<br>b = origin.b<br>console.log(a); // 1<br>console.log(b); // 2</pre><p>是不是有白冰冰變范冰冰的氣勢?</p><p>夠聰明的你，現在可能會問:「實務上，Destructuring 能帶來甚麼幫助呢?」</p><p>舉個簡單的例子，今天我們要實作一個創造一台新車的 Function，可以選擇車子的<strong>廠牌、型號、顏色、排氣量</strong>，這個 Function 可能會長成這樣</p><pre>function createCar(brand, type, color, displacement) {</pre><pre>  // 造車程序...<br><br>}</pre><pre>createCar(&#39;Ford&#39;, &#39;FIESTA&#39;, &#39;Gray&#39;, &#39;998 cc&#39;)</pre><p>乍看好像沒甚麼問題，那如果是在隔了一百多行後又呼叫了一次這個 Function 呢? 這時候可能就記不得 <em>createCar()</em> 帶的參數順序了吧? 你名義同事也拿著刀非常火地在背後問你寫這是三小了吧?</p><p>這時候只要改寫成這樣</p><pre>function createCar(<strong>{brand, type, color, displacement}</strong>) {</pre><pre>// 造車程序...<br><br>}</pre><pre>const newCar = {<br>  brand: &#39;Ford&#39;,<strong><br></strong>  type: &#39;FIESTA&#39;,<br>  color: &#39;Gray&#39;,<br>  displacement: &#39;998 cc&#39;<br>}</pre><pre>createCar(newCar)</pre><p>水腦同事的失憶症，bye bye~</p><p>現在的你已經不再是個普通的臭宅了，接著來點進階的<br>我們來重溫抽學伴，班上公關拿了一份好不容易才願意跟我們交換MSN的文組學伴列表，上面有每個學伴的<strong>名稱、顏值、MSN</strong></p><p>一看，怎麼會有這麼醜的API，讓我們來把它美化一番</p><pre>// 文組學伴給的格式<br>const meiMeis = [<br>  [&#39;Amy &#39;, 90, &#39;amy@msn.com&#39;],<br>  [&#39;Brenda&#39;, 92, &#39;brenda@msn.com&#39;],<br>  [&#39;Carol&#39;, 88, &#39;carol@msn.com&#39;],<br>  [&#39;Debbie&#39;, 95, &#39;debbie@msn.com&#39;]<br>]</pre><pre>// 希望的格式<br>const newMeiMeis = [<br>  {name: &#39;Amy&#39;, yenValue: 90, msn: &#39;amy@msn.com&#39;},<br>  {name: &#39;Brenda&#39;, yenValue: 92, msn: &#39;brenda@msn.com&#39;},<br>  {name: &#39;Carol&#39;, yenValue: 88, msn: &#39;carol@msn.com&#39;},<br>  {name: &#39;Debbie&#39;, yenValue: 95, msn: &#39;debbie@msn.com&#39;}<br>]</pre><p>透過 Destructuring 我們可以優雅的這麼作</p><pre>const newMeiMeis = meiMeis.map(([name, yenValue, msn]) =&gt; {<br> return {name, yenValue, msn}<br>})</pre><p>好囉，有了漂亮的格式，臭宅們現在可以更方便的寫個函式把學伴們全都加進好友名單囉~</p><p>接著把壓軸搬給各位穿著燕尾服的臭宅們看看，同事們要團購，當然不會找我們這樣的邊緣人，但是身為工具人，我們得幫點忙，數組 <em>[300, 600, 20, 90] </em>是同事們訂購商品的價格，每個商品各有十個人訂購，我們要把它生成一個每個數字都變十倍的數組 <em>[3000, 6000, 200, 900]</em>，讓數學差到不行的工讀生方便去匯款</p><p>當然，這邊我們可以用 <em>map</em>、<em>forEach</em>、甚至是 <em>reduce </em>等 helper 輕鬆做到同樣的效果，不過還是讓我有個理由秀秀 Destructuring 的優雅吧</p><pre>const prices = [300, 600, 20, 90]</pre><pre>const counter = ( [price, <strong>...rest</strong>] ) =&gt; {<br>  return price == null ? [] : [price * 10, <strong>...counter(rest)</strong>]<br>}</pre><pre>counter(prices) // <em>[3000, 6000, 200, 900]</em></pre><p>對，我們又更靠近優雅一步了<br>如果現在沒辦法從你的任何角度找到跟金城武的相似之處</p><p>沒關係，至少...你是個好人</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*89qpLpw18VErKc_3fUXWWw.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=264d2b6b2f5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/osakihsieh/%E6%BB%BF%E6%BB%BF%E7%9A%84%E5%A4%A7-es6-destructuring-264d2b6b2f5f">滿滿的大 ES6 - Destructuring</a> was originally published in <a href="https://medium.com/osakihsieh">前端急制</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>