<?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 Chaim Friedman on Medium]]></title>
        <description><![CDATA[Stories by Chaim Friedman on Medium]]></description>
        <link>https://medium.com/@ChaimF?source=rss-9ce5dbe4f830------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4-j_Ijj0nYHcm0BkOYgEmg.jpeg</url>
            <title>Stories by Chaim Friedman on Medium</title>
            <link>https://medium.com/@ChaimF?source=rss-9ce5dbe4f830------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 11:29:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ChaimF/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[The Relationship Between Immutable Data and React Performance]]></title>
            <link>https://medium.com/@ChaimF/the-relationship-between-immutable-data-and-react-performance-8e76e32c6bea?source=rss-9ce5dbe4f830------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e76e32c6bea</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Chaim Friedman]]></dc:creator>
            <pubDate>Mon, 12 Feb 2018 21:36:55 GMT</pubDate>
            <atom:updated>2018-02-12T21:36:55.046Z</atom:updated>
            <content:encoded><![CDATA[<p>Why is it that React and redux seem to put such an emphasis on not mutating state? The answer; performance. How? Well I am glad you asked.</p><p>React has a lifecycle method called shouldComponentUpdate which essentially gives you the chance to tell React when to render this component, and when to leave it as is. In this method you get nextProps as well as your nextState passed in, and you can now compare them to the old props and state respectively. The code would look something like this.</p><pre>shouldComponentUpdate(nextProps, nextState) {<br>  if(nextProps === this.props) {<br>      return false;<br>  } else {<br>    return true;<br>  }<br> }</pre><p>The above code is rather simple. If nextProps is the same as this.props do not render this component again, otherwise go ahead and render. While this code seems simple enough, there is a problem. Comparing objects in JavaScript will return true (as in they are the same) even when they may actually be different. Allow me to illustrate this point with the following example.</p><pre>const obj1 = {<br>    name: &#39;John&#39;<br>};</pre><pre>const obj2 = obj1;</pre><pre>obj2.name = &#39;Jane&#39;;</pre><pre>console.log(obj1 === obj2); // true</pre><p>If you follow the above code, you will see that obj1.name is actually John while obj2.name is actually Jane, yet JavaScript still considers these two objects to be the same. The reason for this is as follows. At first, I created an object called obj1 later when I wrote const obj2 = obj1 I did not in fact create a new object called obj2 . In other words, all I really did was pass the reference to my object from a variable called obj1 to a variable called obj2 . This can be seen when running the following code.</p><pre>const obj1 = {<br>    name: &#39;John&#39;<br>};</pre><pre>const obj2 = obj1;</pre><pre>obj2.name = &#39;Jane&#39;;</pre><pre>console.log(obj1.name); //Jane<br>console.log(obj2.name); //Jane</pre><p>Even though I only changed the value of name on obj2 this change will still get reflected on obj1 because they are both really the same object.</p><p>Now we can understand the importance of immutable data in React. In the life cycle method of shouldComponentUpdate we are essentially comparing objects, but as we have just seen that it not so simple. You might at this point be thinking “why not simply traverse down both objects and see if all the keys are the same?”. This can work, but it can also be pretty slow, and any performance gain acquired through shouldComponentUpdate can get lost when the objects are complex. This is where immutable data comes in to play. If we never mutate state, but rather always create a new object, comparing the objects becomes super easy and fast no matter the size or complexity of the objects. If the objects being compared are not pointing to the same spot in memory, that must mean that the data is not same, and it’s time for a new render.</p><p>Thank you for reading. Hope this clarifies the topic for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e76e32c6bea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript’s this keyword demystified]]></title>
            <link>https://medium.com/@ChaimF/javascripts-this-keyword-demystified-939919d26941?source=rss-9ce5dbe4f830------2</link>
            <guid isPermaLink="false">https://medium.com/p/939919d26941</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Chaim Friedman]]></dc:creator>
            <pubDate>Fri, 09 Feb 2018 20:51:39 GMT</pubDate>
            <atom:updated>2018-02-09T20:51:39.100Z</atom:updated>
            <content:encoded><![CDATA[<p>Perhaps you are wondering why you need to bind your methods in a react component, or maybe this question came up in an interview, but chances are if you worked in JavaScript for at least five minutes, you’ve come across the this keyword in JavaScript. My goal is to try and make this somewhat confusing topic, as clear as possible.</p><p>Imagine your’e having a conversation with a friend, and he randomly blurts out, “yea that was an awesome movie”. You would undoubtedly be scratching your head trying to understand what he’s talking about. Essentially your’e missing context. In other words, you don’t understand to which part of your conversation that statement belongs. On the other hand, if you were currently discussing a specific movie, and your friend then proceeds to make that same statement, you would of course understand his intentions because now you have context.</p><p>With that introduction out of the way, lets take the a look at the following example.</p><pre>const person = {<br> name: ‘Jane’,<br> printName: function() {<br> console.log(this.name);<br> }<br>}</pre><pre>person.printName(); // Jane</pre><p>When JavaScript comes across the this keyword inside of the printName method, it will look for context. In other words, who does the name property belong to. The way JavaScript will figure this out is by looking at the call site of the function. In this case it would be the person object calling the function as is evidenced from person.printName(). Now JavaScript understands that the name property hanging off of this belongs to person, and given that the person object does in fact have a name property on it, the output will be Jane.</p><p>To illustrate this point even more, let’s consider the above example, with one seemingly minor tweak.</p><pre>const person = {<br> name: ‘Jane’,<br> printName: function() {<br> console.log(this.name);<br> }<br>}</pre><pre>const printName = person.printName;<br>printName(); // undefined</pre><p>As you can see the code is almost identical, except for the fact that now I am assigning the person.printName method to a local variable. Seems like a small change, but that small detail makes all the difference. Remember that JavaScript looks for context. In other words, who does the name property belong to. The way JavaScript gets that context is by looking at who is calling the function. Earlier, the function was actually called by person, and person does in fact have a name property on it, but now it’s global calling the function, or in the case of the browser it would be window calling it. Therefore, JavaScript does not know who the name property belongs to.</p><p>As a general rule of the thumb, to know what this is referring to when coming across it in a function, looking at the call site of the function will give you all the information you need.</p><p>There are of course a few caveats to that, so I would recommend reading about <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call">call</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind">bind</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply">apply</a>.</p><p>Thank you for reading. I hope this helps!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=939919d26941" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>