<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nick Mulder</title>
    <description>The latest articles on DEV Community by Nick Mulder (@muldernick).</description>
    <link>https://dev.to/muldernick</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F323511%2Fecefa5b6-605f-4210-83d1-d86f6369a7be.png</url>
      <title>DEV Community: Nick Mulder</title>
      <link>https://dev.to/muldernick</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muldernick"/>
    <language>en</language>
    <item>
      <title>How to properly extend JS native Classes</title>
      <dc:creator>Nick Mulder</dc:creator>
      <pubDate>Fri, 24 Jan 2020 19:45:08 +0000</pubDate>
      <link>https://dev.to/muldernick/how-to-properly-extend-js-native-classes-kpa</link>
      <guid>https://dev.to/muldernick/how-to-properly-extend-js-native-classes-kpa</guid>
      <description>&lt;p&gt;In many cases it can be useful to extend native Javascript classes. Though you should be careful as unwanted side-effects might be difficult to pin down. In this example we will be extending the Array class with a simple immutable remove function.&lt;/p&gt;

&lt;p&gt;In order the extend a class we want to add a property to the &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes"&gt;object's prototype&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We could simply do the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IEbnbMNF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1wvi2hd7vq3srtc7wwfr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IEbnbMNF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1wvi2hd7vq3srtc7wwfr.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we directly extend the classes prototype. We however lack control to define detailed behavior. This causes unwanted side-effects. One of the side-effects is that the property is Enumerable. This causes it to be part of values when using a for...in loop. In order to circumvent this issue and get more control we can instead do the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0or7LNFE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/guoep0ww5br7e5ztamub.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0or7LNFE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/guoep0ww5br7e5ztamub.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty"&gt;Object.defineProperty&lt;/a&gt; we are able to control the attributes of our new property.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>productivity</category>
      <category>codequality</category>
    </item>
  </channel>
</rss>
