<?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 Jeff Lau on Medium]]></title>
        <description><![CDATA[Stories by Jeff Lau on Medium]]></description>
        <link>https://medium.com/@_jefflau?source=rss-237fa4f19f6c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*L2r15zdnDUTvmGj7.jpeg</url>
            <title>Stories by Jeff Lau on Medium</title>
            <link>https://medium.com/@_jefflau?source=rss-237fa4f19f6c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:36:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@_jefflau/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[New Text Records Now Available for ENS Names in Manager]]></title>
            <link>https://medium.com/@_jefflau/new-text-records-now-available-for-ens-names-in-manager-a0ebb9cda73a?source=rss-237fa4f19f6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0ebb9cda73a</guid>
            <category><![CDATA[ethereum-name-service]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[en]]></category>
            <category><![CDATA[record]]></category>
            <category><![CDATA[text-record]]></category>
            <dc:creator><![CDATA[Jeff Lau]]></dc:creator>
            <pubDate>Thu, 03 Oct 2019 18:26:54 GMT</pubDate>
            <atom:updated>2019-10-03T18:26:54.424Z</atom:updated>
            <content:encoded><![CDATA[<h3>Text Records Now Available for ENS Names in Manager</h3><p>Text records have been implemented in the Public Resolver contract for a while now, but there hasn’t been an easy interface to use them. That all changes now as we’ve just released new text record support in the <a href="https://manager.ens.domains/">Manager</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gSLa69XWbro-1fXLFplMLw.png" /></figure><h3>What are they for?</h3><p>Text records are for any arbitrary data you want to attach to an ENS name. At the moment, we are supporting the keys defined in the <a href="https://eips.ethereum.org/EIPS/eip-634">original text record EIP</a> by Richard Moore, which include keys for an email address, URL, social media profiles, and other meta data of your choosing.</p><p>In the future, hopefully you can use ENS names to add profile information to each app you use as easily as adding in your ENS name, similar to <a href="https://en.wikipedia.org/wiki/Gravatar">Gravatar</a>, but entirely decentralized. When you change your profile on ENS, it will automatically update on each app.</p><h3>How can I add a text record?</h3><p>In the <a href="https://manager.ens.domains/">ENS Manager</a>, once you have the Public Resolver set on your name, you can just add a record by clicking the ‘+’ button in the ‘records’ tab:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1kw9IfhIQkdtFSKz_NlZeg.png" /></figure><p>Once you have clicked that, you should see some drop down boxes appear that will allow you to choose to add a “TEXT” record, the kind of text record (e.g. “URL”), and then enter the information for that record:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tuRfkeDtttdgSTaEUnfVSA.png" /></figure><p>Once you’re ready, click save to send the transaction, and once it’s mined you should see it appear below.</p><p><strong>Note</strong>: Text records, like all ENS records, are publicly available.</p><h3>What’s next for text records?</h3><p>We would like to see how people use them, and once the basic version is in use, we plan to allow arbitrary text record types to be set in the Manager.</p><p>This will mean you will be able to add your own custom text record keys that we haven’t thought of. However if you have an idea for a great text record type right now, please let us know in <a href="https://discuss.ens.domains/">our forum</a>, as the most useful text records are the ones used by everyone!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0ebb9cda73a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New React ENS Address Component Let’s You “Drop-In” ENS Support to Your Dapp]]></title>
            <link>https://medium.com/@_jefflau/new-react-ens-address-component-lets-you-drop-in-ens-support-to-your-dapp-b31863ba85a6?source=rss-237fa4f19f6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b31863ba85a6</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[domains]]></category>
            <category><![CDATA[ethereum-name-service]]></category>
            <dc:creator><![CDATA[Jeff Lau]]></dc:creator>
            <pubDate>Wed, 17 Jul 2019 17:36:41 GMT</pubDate>
            <atom:updated>2019-07-17T17:37:46.861Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ob5e4JTjEvP6BIM_Jiuasg.png" /></figure><p>Last week in the <a href="https://ens.domains/">Ethereum Name Service</a> (ENS) <a href="https://manager.ens.domains/">Manager app</a> we released a new feature where you can type an ENS name into any address field and it will resolve to the address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*tOgrtJbJGiRWK0BqOD1_ag.gif" /><figcaption>Normal name resolution</figcaption></figure><p>You can also type in addresses and it will give you the reverse resolution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*pAEacMwFM5Ldeoi2clltLw.gif" /><figcaption>Reverse resolution</figcaption></figure><p>It will also give you the blockies icon so you know if it matches your address or not. It makes it much easier to set up new names with the same address and you just need to type in your ENS name that has addresses setup.</p><p>The aim for this component was always to make it easier for people to use ENS in their own app and so we packaged this up and turned it into an npm package so you can use it in your React app too!</p><p><strong>Introducing </strong><a href="https://www.npmjs.com/package/@ensdomains/react-ens-address"><strong>react-ens-address</strong></a><strong>, a drop-in component for text inputs.</strong> Instead of just taking addresses for your dapp, you can now use ENS to make it easier for your users to add their address to your app. The setup is as simple as importing our component as follows and giving it a provider:</p><pre><strong>import</strong> ENSAddress <strong>from</strong> &#39;@ensdomains/react-ens-address&#39;</pre><pre>&lt;ENSAddress <strong>provider</strong>={window.web3 <strong>||</strong> window.ethereum} /&gt;</pre><p>The component at the most basic level takes an onResolve function that fires when the component finishes resolving the input</p><pre>&lt;ENSAddress <br>  provider={window.web3 || window.ethereum} <br>  onResolve={({ address, name, type }) =&gt; {<br>    if(type === &#39;name&#39;){<br>      console.log(address)<br>    }</pre><pre>    if(type === &#39;address){<br>      console.log(name)<br>    }<br>  }}<br>/&gt;</pre><p>The type is the type of value of the input, which is detected by the component, so you can expect if the input is an ENS name, it will resolve to an address and vice versa!</p><p>We are always looking for ways for people to integrate ENS in their dapps and if the community wants to contribute to an Angular or Vue component, that would also be really helpful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b31863ba85a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Cryptokitties is more than just cats]]></title>
            <link>https://medium.com/@_jefflau/why-cryptokitties-is-more-than-just-cats-c7e7f1418ff2?source=rss-237fa4f19f6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7e7f1418ff2</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[cryptokitties]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[cats]]></category>
            <dc:creator><![CDATA[Jeff Lau]]></dc:creator>
            <pubDate>Mon, 04 Dec 2017 16:17:52 GMT</pubDate>
            <atom:updated>2017-12-04T16:17:52.098Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y6jPwkFXw_mQG25jTYcuow.png" /></figure><p>Although the idea that cats being the first things to bring Ethereum and blockchain gaming into mainstream is both hilarious and unsurprising, the significance of cryptokitties is more than just about cute furry animals being traded for obscene amounts of money. There have been many comparisons to neopets, pokemon trading cards and other collectibles, which really brought me back to the good old days for buying packs just to get those trusty ‘shinies’ we used to call them in the UK. But as much as I want to reminisce on the past, what cryptokitties proves is that you can tokenise anything on the blockchain.</p><p>ERC20 has been the craze of 2017 allowing the trade of fungible tokens that have been the defacto compensation for participating in an ICO, but we have yet to see the rise of a token standard that will allow non-fungible (unique) assets. The <a href="https://github.com/ethereum/EIPs/issues/721">ERC721 standard</a> is aiming to cover NFTs (Non-fungible tokens), and even if it just starts with digital assets, such as the ownership of a piece of limited edition digital art, time-limited membership to an online course (that could be paused), it could quickly be made to represent real world things such as houses, gym memberships, rental agreements that could be transferred without so much hassle or redrawing the contract. It is much harder to create a standard that allows for an indefinite amount of variations, but not only is cryptokitties pushing the boundaries of what the Ethereum network can handle, it is also showing that non-fungible tokens are possible and they work.</p><p>This is what we have been dreaming of. The ability to easily trade assets creates markets that none of us have ever dreamed of. It reduces barriers, costs and friction where there shouldn’t be any. 2018 could be the year of the NFTs</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7e7f1418ff2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A journey through ES6 — Destructuring]]></title>
            <link>https://medium.com/@_jefflau/a-journey-through-es6-destructuring-9e5f4a63a46a?source=rss-237fa4f19f6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e5f4a63a46a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[destructuring]]></category>
            <dc:creator><![CDATA[Jeff Lau]]></dc:creator>
            <pubDate>Sat, 03 Oct 2015 10:24:51 GMT</pubDate>
            <atom:updated>2015-10-03T10:24:51.913Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Note: Since Medium doesn’t support syntax highlighting for code the original article was written here. Go there if you want to copy any code snippets:</em><a href="https://gist.github.com/jefflau/90ecf88a2818f52cae49"><em>https://gist.github.com/jefflau/90ecf88a2818f52cae49</em></a></p><p>Destructuring is a very useful technique in ES6. It allows you to ‘break down’ or ‘deconstruct’ an object into variables. Think of it like flattening the object so all the properties and value come out as normal variables.</p><h3>Simple Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kW8P10FbOB2qXnAgpHnbmw.png" /></figure><h3>Simple Practical Example</h3><p>A practical example of using destructuring is when passing an object as options to a function. For instance if you were setting up a slider that might have a lot of options, you would want to pass an options object instead of arguments. This would create a cleaner API so you don’t need to remember the position of the parameters in your slider. This is where destructuring is a perfect fit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ERsaYVpI_MuIVJ3SHyQoHQ.png" /></figure><h3>Simple Practical Example 2</h3><p>You can also destructure straight into the function parameters so you make even more concise and get rid of the options argument entirely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2mSnBOf_ailwYU2gFvbMw.png" /></figure><h3>Destructuring Arrays</h3><p>Destructuring is not just limited to objects either, you can also destructure arrays.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nmK4xIU8nXc3lKf0G4EixA.png" /></figure><h3>Returning multiple values from a function</h3><p>Similar to the practical example before, you can destructure return values whether they are object or arrays and easily destructure them in one statement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zbwoYRt6j7j4FTBuxljmnA.png" /></figure><h3>Changing the variable names</h3><p>It would seem so far that you can only destructure objects with the same variables names as the property names, but actually you an assign whatever names you want, but you need to use a slightly longer syntax.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pbNyfWK1lRnFGobZivoT9g.png" /></figure><p>What’s confusing now is which one is the variable name and which one is the property name in the object? Well, if you think of it like a normal object {a: 42}. The property name in the object when destructuring never moves. So you would place the rename where the value would usually be so var {a: newName} = {a: 42} would create a variable newName with the same value as the property a inside the object. Therefore to destructure the last object with a different name you can do this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gebw_k8uep_cGxmTxj0dwQ.png" /></figure><p>If you remember the name of the property never moves, you shouldnt have a problem remembering how the long version works! I don’t use this that often, but it might be useful for creating a new object from an old object and changing the names where they don’t make sense.</p><h3>Default values</h3><p>We can also create default value assignments for a variable that might not exist on the object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*olMF6tEUAFNmZq5FA5Pisg.png" /></figure><h3>Slightly more advanced practical example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DBYqrY2lSKxELRde5Em1zw.png" /></figure><p>In this example we have a two functions, the displaySmallProduct function goes and gets the productImages for that particular product, the function returns an object that contains more values than we need about the medium and large images. So when we destructured the object, we simply omitted those values. The name and createdDate make sense for this example and therefore we use the short syntax where it will match the name for us. However this particular case we should change the name from small to something more relevant such as url, so make the code more readable so instead of {name, createdDate, small}, we can write the long syntax just for small so we get {name, createdDate, small: url}.</p><h3>Wrapping Up</h3><p>Destructuring is super useful in its simplest form, especially for option type objects and for readability. It is also very powerful and you can also start to destructure nested objects and arrays, but once you start mixing the short and long syntax, changing variable names, it starts to become harder and harder to read.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NFgeU-iVEfPkzZyfc-IexA.png" /></figure><p>I’ve written about practical examples that I use everyday, but there’s a lot more to destructuring that you can learn. The last example I gave I would not use destructuring as to even make it remotely readable you need to indent it, and its also a lot more typing and still less readable. Once you’ve learnt how destructuring works it can be easy to go overboard and destructure absolutely everything, but you might be the only one able to read it, so use it only when it makes sense!</p><h3>References and Further Reading</h3><p><a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment</a> <a href="https://hacks.mozilla.org/2015/05/es6-in-depth-destructuring/">https://hacks.mozilla.org/2015/05/es6-in-depth-destructuring/</a></p><p><em>Originally published at </em><a href="https://gist.github.com/jefflau/36dc22f2fe7dc3492850"><em>gist.github.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e5f4a63a46a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A journey through ES6 — Arrow Functions]]></title>
            <link>https://medium.com/@_jefflau/a-journey-though-es6-arrow-functions-7822fe3215e4?source=rss-237fa4f19f6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7822fe3215e4</guid>
            <category><![CDATA[function]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Jeff Lau]]></dc:creator>
            <pubDate>Tue, 29 Sep 2015 10:20:58 GMT</pubDate>
            <atom:updated>2015-09-29T10:24:08.152Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Note: Since Medium doesn’t support syntax highlighting for code the original article was written here. Go there if you want to copy any code snippets: </em><a href="https://gist.github.com/jefflau/90ecf88a2818f52cae49"><em>https://gist.github.com/jefflau/90ecf88a2818f52cae49</em></a></p><p>Arrow functions (also known as fat arrow functions) are awesome. They do two main things for you. Create a shorter syntax, and lexically scope `this`.</p><h3>Shorter syntax</h3><pre>//ES5 <br>[1, 2, 3].map(function(n){ return n + 1 } // [2, 3, 4] </pre><pre>//ES6 <br>[1, 2, 3].map(n =&gt; n + 1) // [2, 3, 4]</pre><p>Heres a few rules for this shorter syntax</p><ul><li>The parentheses are optional for a single argument (unless you’re using ES6 features rest, destructuring). A function with no argument still needs the parentheses</li><li>If the function is just a single line express you can omit the return statement and omit the `{}` surrounding the function block</li><li>If your single line expression returns an object, you must wrap it with `()` so it’ll look like: `({a: 1, b: 2})`</li></ul><p>Check this awesome diagram by <a href="http://twitter.com/getify">@getify</a> for further clarification</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*yaOK-WIPbbghH2h2Oo2ZqA.png" /></figure><p>If your function isn’t so simple we’ll have to do this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*buO7xc1j9_FxtwSAksMDew.png" /></figure><h4>Implicit return with object literals</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*abRM59n0kYIplUKOIxAJ4Q.png" /></figure><h3>Lexically scoping `this`</h3><p>With Javascript now we have some annoying issues with callbacks and the binding of this. The classic cases is when we pass an eventHandler a callback, but the this object is not bound to what we want. This means we need to use the `.bind()` method on the Function.prototype object or we have to bind this lexically to a variable such as var self = this.</p><p>With Arrow functions in ES6, arrow functions do not automatically gain their own this, they simply get it lexically from their enclosing scope and therefore alleviate this problem when we pass our callback to a function that assigns our this to something else.</p><h4>ES5 Problem</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1oxddoG6I4YtGdJRqdCWNw.png" /></figure><h4>ES5 Solution 1</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vUZaxlvdSGNvoPc-aYGATw.png" /></figure><h4>ES5 Solution 2</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XDyLXJUtiI44q5SHSwpjEw.png" /></figure><h4>ES6 Solution</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XDyLXJUtiI44q5SHSwpjEw.png" /></figure><p>As you can see the ES6 solution is a lot cleaner and saves you thinking about hard binding this using bind or littering your code with unnecessary `var that = this` or `var self = this`</p><h3>A couple caveats</h3><ul><li>Arrow functions do not have their own arguments variable like normal functions, but if you’re using ES6 you can use rest parameter or default values</li><li>Arrow functions are always anonymous and therefore cannot be called recursively from inside itself. So you can’t do recursion</li></ul><h3>Further reading and references</h3><p><a href="https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20&amp;%20beyond/fig1.png">https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20&amp;%20beyond/fig1.png</a> <a href="https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/">https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/</a></p><p><em>Originally published at </em><a href="https://gist.github.com/jefflau/90ecf88a2818f52cae49"><em>gist.github.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7822fe3215e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A journey through ES6 — let and const]]></title>
            <link>https://medium.com/@_jefflau/a-journey-through-es6-let-and-const-7223df1f9cad?source=rss-237fa4f19f6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7223df1f9cad</guid>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[etl]]></category>
            <dc:creator><![CDATA[Jeff Lau]]></dc:creator>
            <pubDate>Fri, 11 Sep 2015 13:50:36 GMT</pubDate>
            <atom:updated>2015-09-11T13:50:36.620Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve just started learning ES6 properly and to help others I’m going to document what I’ve learnt through a series of blog posts. In this post we’re going to start with the most basic parts of ES6 that you can jump into straight away. let and const are two new keywords for defining variables. Both are really simple to use and solve some problems in the JavaScript language.</p><h3>let</h3><p>We’ll start looking at let first. JavaScript’s scoping is done with functions. That means anything declared as a var inside a function closure will be only accessible within the function. One thing JavaScript didn’t have before ES6 was block scoping, and that is where let comes into play. Block scoping is scoping within a ‘block’. That block is denoted by the { … } curly braces in JavaScript.</p><p>let allows you to create block scopes</p><pre>{ <br>  let x = 2 <br>} </pre><pre>console.log(x) //undefined</pre><p>You might find the syntax of `{ … }` within an if statement or for loop a little strange, but it always has been valid JavaScript, albeit a little useless without block scoping, but it is more commonly used in other languages.</p><p>let is most useful in a for loop, where the counter variable is declared for each iteration of a loop, so you don’t get issues with callback functions where the callback hasn’t been called yet, and so it uses the last iteration of the loops value.</p><pre>var array = [1, 2, 3]; </pre><pre>for (var i = 0; i &lt; array.length; i++) { <br>  setTimeout(function () { <br>    console.log(array[i]) <br>  }, i * 1500); <br>}</pre><p>Here, because of the setTimeout the output by console.log(array[i]) will be undefined, because by the time the setTimeout callback is run, the value of i is already 4.</p><p>Another example of this scoping problem is as follows:</p><pre>var funcs = []; </pre><pre>for (var i = 0; i&lt;5; i++) { <br>  funcs.push(function(){ console.log(i) }); <br>} </pre><pre>funcs[1](); //5</pre><p>In the same way as the last example, because of the scoping of var, there isn’t a new variable created for each and every iteration of the loop, so when the `funcs[1]` is called, the value of `i` is already 5.</p><p>Both of these previous examples can be fixed, by replacing the var with let. The reason for this is that let creates a new scope for every iteration of the loop, and therefore when it is called for later on, it is the value it was when that iteration of the loop took place. It’s a little confusing in theory if you’ve never run into this problem before, and you would have to use function closures to get around this deficiency in the language before the let keyword, but all you need to remember is to use let in for loops to get expected behavior.</p><pre>var funcs = []; </pre><pre>for (let i = 0; i&lt;5; i++) { <br>  funcs.push(function(){ console.log(i) }); <br>} </pre><pre>funcs[1](); //1</pre><p>To illustrate how awesome let is. The code below is how you would normally create a closure per iteration. Every iteration of the loop the statement to push the new function into the array is wrapped in an <a href="https://en.wikipedia.org/wiki/Immediately-invoked_function_expression">IIFE</a> (Immediately Invoked Function Expression) to create a new scope for the argument j that is actually just the variable i being passed through the IIFE. Explaining the issues of a lack of block scope is out of the scope of this article (get it?!), but it’s always been a mouthful to write if you need to get around this deficiency in the language. Now that we have let, we can write cleaner easier to understand code.</p><pre>var funcs = []; </pre><pre>for (var i = 0; i&lt;5; i++) { <br>  (function(j){ <br>     funcs.push(function(){ console.log(j); }); <br>  })(i); <br>} </pre><pre>funcs[1](); //1</pre><h4>Temporal Dead Zone</h4><p>If you declare the let variable after you call it, you’ll get a ReferenceError as it is only initialised when you get to the let keyword. If you did the same thing with var, the variable declaration is actually hoisted to the top, so you would get undefined. In short `let` is not hoisted.</p><h3>const</h3><p>const is a little more simple than let. It allows you to create what we’ve stylistically been creating for years with ALL CAPS variables such as:</p><pre>var TRANSITION_INTERVAL = 5000;</pre><p>This can be simply written as:</p><pre>const TRANSITION_INTERVAL = 5000; <br>TRANSITION_INTERVAL = 2000 //TypeError!</pre><p>const will not let you change a primitive value such as numbers or strings. It is not a restriction on the value itself, but of the variable’s assignment of that value. That means that you will be able to mutate an object, by changing a current property or even adding a new one.</p><pre>const TRANSITION_DATA = { <br>  interval: 5000 <br>} </pre><pre>TRANSITION_DATA.interval = 2000; <br>TRANSITION_DATA.type = &#39;fade&#39;;<br> <br>TRANSITION_DATA.type; // &#39;fade&#39; <br>TRANSITION_DATA.interval; // 2000</pre><p><em>Originally published at </em><a href="https://gist.github.com/jefflau/193c2079967901176600"><em>gist.github.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7223df1f9cad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A journey through ES6 — Introduction and setting up]]></title>
            <link>https://medium.com/@_jefflau/a-journey-through-es6-introduction-and-setting-up-6e3a10f70862?source=rss-237fa4f19f6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e3a10f70862</guid>
            <category><![CDATA[babeljs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Jeff Lau]]></dc:creator>
            <pubDate>Sun, 06 Sep 2015 08:43:17 GMT</pubDate>
            <atom:updated>2015-09-06T08:43:17.492Z</atom:updated>
            <content:encoded><![CDATA[<p>I decided to write a series of blog posts to document my journey through ES6(ES2015). I first started learning ES6 because I was using Babel to transform my React JSX code without using another transformer, but at the same time gaining access to the new ES6 features. Gradually I’ve started using more and more of the ES6 features, since they were just there available to me and I have finally decided to put some time into learning ES6 and documenting what I’ve learnt.</p><h3>Setting up</h3><p>To start learning ES6 you’ll have to use something to compile your ES6 code into ES5 code. I use the popular Babel compiler, which also compiles JSX for React code. I’ve made a React/Browserify/ES6 boilerplate, which you can find here. You’ll need to install the dependencies with npm and then run gulp and it’ll automatically run a server at localhost:3000</p><pre>$ npm install -g gulp<br>$ npm install<br>$ gulp </pre><p><a href="https://github.com/jefflau/react-browserify-boilerplate">jefflau/react-browserify-boilerplate</a></p><p>If you’d rather use something like <a href="http://codepen.io/">codepen.io</a> they also support Babel, and you can find the instructions for setup here:</p><p><a href="http://blog.codepen.io/2015/05/19/babel-now-on-codepen-write-es6-javascript-and-react-jsx/">http://blog.codepen.io/2015/05/19/babel-now-on-codepen-write-es6-javascript-and-react-jsx/</a></p><p>I prefer to learn in the context of creating app, so I’ve created a boilerplate in React that you can start to learn ES6 in a real environment. If you don’t use React or don’t want to use React, you can still use the boilerplate. Everything is bundled using Browserify, and is using the ES6 modules system (as opposed to CommonJS) and starts from the app.js file and you can just start writing your JS code from there.</p><p>ES6 is the biggest change to Javascript since ES5 in 2009, and there are a lot of new features such as block scoping, classes and destructuring that we all need to learn. It’s finally a standard now, and we don’t need to wait for it to be implemented in every browser to start using it. Even when all of ES6 is implemented in every browser, we’ll still need transformers like Babel so we can use the newest features from ES7 and beyond!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e3a10f70862" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>