<?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: went</title>
    <description>The latest articles on DEV Community by went (@wentout).</description>
    <link>https://dev.to/wentout</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%2F311947%2F243477ba-1924-4ade-ad8d-1f174d9a09bf.jpeg</url>
      <title>DEV Community: went</title>
      <link>https://dev.to/wentout</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wentout"/>
    <language>en</language>
    <item>
      <title>Dead Simple type checker for JavaScript</title>
      <dc:creator>went</dc:creator>
      <pubDate>Thu, 19 Mar 2020 19:26:43 +0000</pubDate>
      <link>https://dev.to/wentout/dead-simple-type-checker-for-javascript-4l40</link>
      <guid>https://dev.to/wentout/dead-simple-type-checker-for-javascript-4l40</guid>
      <description>&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Type_system#Type_checking"&gt;Type Checking&lt;/a&gt; in JavaScript is very complicated for beginners. There are only &lt;a href="https://en.wikipedia.org/wiki/Data_type"&gt;Data Types&lt;/a&gt;. And everything the rest is something very different from well known and common used meaning of Types. We might be having &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt; or something derived from &lt;code&gt;Object&lt;/code&gt; or other constructors. And any derived from Object is not a Type, but Structures. And this might seem very opinionated and dependent from JavaScript Engine, but &lt;code&gt;undefined&lt;/code&gt; has it's own &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new"&gt;Constructor&lt;/a&gt;, and when we make  "&lt;code&gt;void 0&lt;/code&gt;" will invoke that constructor for new memory pointer marked as &lt;code&gt;undefined&lt;/code&gt; data. Therefore there is a lot of misunderstanding and misconceptions for those are new with JavaScript world. Sometimes it even harder for developers used to study with Strict Typing Systems in mind, but anyway, there are many pitfalls in general.&lt;/p&gt;

&lt;h1&gt;
  
  
  Concept
&lt;/h1&gt;

&lt;p&gt;Each constructed structure has &lt;code&gt;instance.constructor.name&lt;/code&gt;, where &lt;code&gt;instance&lt;/code&gt; is a pointer to our variable and &lt;code&gt;.constructor.name&lt;/code&gt; is obligatory path, pointing us to the name of constructor invoked during instance creation. Therefore all non primitive so-called "types" has &lt;code&gt;.constructor.name&lt;/code&gt;. And what is "non primitive" then? Eh... non Data Types, but something else. And Data Types is that sort of thing which marks memory allocation as a type: data &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures"&gt;Primitives&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Boolean&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;String&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Number&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Symbol&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;BigInt&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and not so about data, but primitive of everything wich we discuss more in a moment below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;null&lt;/code&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And isn't it true that all these have constructors? Indeed, they do. But wich sort of constructor do they have? There is a bit difference: constructors for primitives do memory allocations for Data, and they then answers the question "which data type is that allocated memory".&lt;/p&gt;

&lt;p&gt;It is not so special, but it is different from everything the rest in JavaScript: when other constructors are for Structures, not for Data.&lt;/p&gt;

&lt;p&gt;And there is one very special thing: superheroic &lt;code&gt;null&lt;/code&gt;, which allows us to have all the other constructors. And din't &lt;code&gt;null&lt;/code&gt; has own constructor itself? As it is the only SuperDuperPuperClass, and &lt;a href="https://en.wikipedia.org/wiki/Singleton_pattern"&gt;Singleton&lt;/a&gt; we might say yes and no, simultaneously. And it is the only thing the other thing are derived from. It is so special and the same place so simple: but nobody cares of it, we just used to hate &lt;code&gt;typeof null === 'object'&lt;/code&gt; and that is it. But instead of doing this, please just look for the whole system. It is simple, straight, and it might be said: "it is &lt;a href="https://en.wikipedia.org/wiki/Complete_metric_space"&gt;Full&lt;/a&gt;".&lt;/p&gt;

&lt;p&gt;Again: there are only Data Types and Structures soo what is the Next Step? Yes, there is a next step. And this step is &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof"&gt;&lt;code&gt;instanceof&lt;/code&gt;&lt;/a&gt;. When we construct something, we might be willing to check if we did construction from exactly that constructor in future. And this points us to the next big question in JavaScript: &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Inheritance"&gt;Inheritance&lt;/a&gt;. It might be the other even greater complicated topic, no matter how many times you've read about it.  And from the other side there are not so many developers who was able to explain this topic well in each aspect. Remembering the early dates when there was a war between Netstcape Navigator and Internet Explorer 3~4 even I did two novelistic memoirs, please forgive me suggesting it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Romantic, with only one example: &lt;a href="https://dev.to/wentout/architecture-of-prototype-inheritance-in-javascript-ce6/edit"&gt;Architecture of Prototype Inheritance in JavaScript&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Nostalgic, with a lot of memories behind, few examples: &lt;a href="https://dev.to/wentout/inheritance-in-javascript-factory-of-constructors-with-prototype-chain-point-of-view-from-boring-nerd-2ddb"&gt;Inheritance in JavaScript : Factory of Constructors with Prototype Chain : point of view from boring nerd&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Starting from this is a moment I have to say sorry again, because now I will think we can share the same meanings.&lt;/p&gt;

&lt;p&gt;Therefore we might succeed everything constructed has an &lt;code&gt;instance.consructor.name&lt;/code&gt;. But as we saw there is another big thing for Constructed: where constructible function meet &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes"&gt;Prototype&lt;/a&gt; being invoked with &lt;code&gt;new&lt;/code&gt; keyword. And we can rely on it, safely. The only exclusion is &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create"&gt;&lt;code&gt;Object.create&lt;/code&gt;&lt;/a&gt;, but even then, there was construction derived from prototype, though constructor was &lt;code&gt;Object&lt;/code&gt; itself. And we might be saying that &lt;code&gt;{}&lt;/code&gt; or &lt;code&gt;[]&lt;/code&gt; have not yet being constructed? But there is no other way to simplify this process, so it was just &lt;a href="https://en.wikipedia.org/wiki/Lexical_analysis"&gt;lexer&lt;/a&gt; helping us with AST making special notes for messing up &lt;code&gt;[]&lt;/code&gt; with &lt;code&gt;new Array&lt;/code&gt; and &lt;code&gt;{}&lt;/code&gt; with &lt;code&gt;new Object&lt;/code&gt;. And even deeper, as Arrays are derived from Objects, so by the &lt;code&gt;typeof&lt;/code&gt; checker &lt;code&gt;Array&lt;/code&gt;s are &lt;code&gt;Object&lt;/code&gt;s. This is done that way because &lt;code&gt;typeof&lt;/code&gt; just checks Data Types (primitives), and &lt;code&gt;Array&lt;/code&gt; is not Data Type, it is a special Structure of the other things. That is why it is an &lt;code&gt;'object'&lt;/code&gt; for &lt;code&gt;typeof&lt;/code&gt; checker.&lt;/p&gt;

&lt;p&gt;Being realistic we can see it is done that way for more than 20 years ago. And it is useless and pointless to think the other way for practical usage, despite we wish the "better". And we might don't like this, but there is true beauty when we accept and understand it instead of hating. It is very useful and very simple when we can rely it without breaking it. And this more than scalable and there are no good points for making it better. "&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this"&gt;This&lt;/a&gt;" system is Full, it is not necessary to extend it with something else.&lt;/p&gt;

&lt;p&gt;As we then see: everything constructed (and derived from null) returns 'object' as a result of &lt;code&gt;typeof&lt;/code&gt; checking. And the special case &lt;code&gt;null&lt;/code&gt; returns &lt;code&gt;object&lt;/code&gt; too, because it points to the &lt;code&gt;.constructor.name&lt;/code&gt; and constructor of &lt;code&gt;null&lt;/code&gt; is &lt;code&gt;Object&lt;/code&gt;, the only thing being singleton &lt;code&gt;null&lt;/code&gt; has no properties. But truth is the following: thinking of data type checking there are no tasks of checking &lt;code&gt;.constructor.name&lt;/code&gt; from &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Keeping all this in mind we might build very simple system. Just being aware of the thing that does yet not implemented, this short sequence of conditional logic:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;get the &lt;code&gt;typeof&lt;/code&gt; of provided &lt;code&gt;instance&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;if this is not an &lt;code&gt;'object'&lt;/code&gt;, then it is a primitive, and we might return the answer right now;&lt;/li&gt;
&lt;li&gt;if it is &lt;code&gt;null&lt;/code&gt; return &lt;code&gt;null&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;if &lt;code&gt;.consructor.name&lt;/code&gt; returns &lt;code&gt;object&lt;/code&gt;, then it is structure, derived strictly from &lt;code&gt;Object&lt;/code&gt; constructor, no matter how;&lt;/li&gt;
&lt;li&gt;if &lt;code&gt;.consructor.name&lt;/code&gt; returns something from primitive constructors, &lt;code&gt;'String'&lt;/code&gt; or &lt;code&gt;'Number'&lt;/code&gt; or .., then the answer is that &lt;code&gt;.name&lt;/code&gt;, for better compatibility let &lt;code&gt;.toLowerCase()&lt;/code&gt; it;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;if &lt;code&gt;.consructor.name&lt;/code&gt; is &lt;code&gt;'Array'&lt;/code&gt;, &lt;code&gt;'Date'&lt;/code&gt;, &lt;code&gt;'Map'&lt;/code&gt;, &lt;code&gt;'WeakMap'&lt;/code&gt;, &lt;code&gt;'Set'&lt;/code&gt;, &lt;code&gt;'WeakSet'&lt;/code&gt; we might again &lt;code&gt;.toLowerCase()&lt;/code&gt; the answer, because mostly this structures are used for storing Data;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I'd personally suggest &lt;code&gt;'RegExp'&lt;/code&gt; and &lt;code&gt;'Promise'&lt;/code&gt; as something very tightly coupled with data, but this is my choice, judge me an Issue;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And yes, there are many types for Errors, and each one of them derives &lt;code&gt;Error&lt;/code&gt;, so this is just an &lt;code&gt;'error'&lt;/code&gt;;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The last thing is &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function"&gt;&lt;code&gt;'Function'&lt;/code&gt;&lt;/a&gt;, and just because this is a very special case, there is a simple answer, we will use direct answer from &lt;code&gt;typeof&lt;/code&gt; received at &lt;code&gt;1.&lt;/code&gt;;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All the other types we might be willing to have in this "type checker" for our new shiny Type System will receive &lt;code&gt;.constructor.name&lt;/code&gt; as an automated Profit! It is not necessary to check them deeper. If we will wish we might rely on &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf"&gt;&lt;code&gt;Object.getPrototypeOf(instance.constructor.name)&lt;/code&gt;&lt;/a&gt;, and we might use underground names of constructors. If we will need it later, we might use &lt;code&gt;instanceof&lt;/code&gt;. But we should rely on our personal feelings about the other modules of our codebase because of the very broken thing comes with &lt;code&gt;Object.create&lt;/code&gt;'s dawn in JavaScript &lt;code&gt;;^)&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;        &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
        &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Object {a: "a"}&lt;/span&gt;
        &lt;span class="nx"&gt;baz&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Object {a: "a"}&lt;/span&gt;
        &lt;span class="nx"&gt;baz&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt; &lt;span class="c1"&gt;// true. oops.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Dear Eric, thank you very much for this example. Here is a link of Your wonderful article &lt;a href="https://medium.com/javascript-scene/common-misconceptions-about-inheritance-in-javascript-d5d9bab29b0a"&gt;Common Misconceptions About Inheritance in JavaScript&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So we will either avoid using &lt;code&gt;Object.create&lt;/code&gt; if we need that checks, or will invent something like hidden &lt;code&gt;Symbol&lt;/code&gt;, pointing us to real constructor.&lt;/p&gt;

&lt;p&gt;Finally if should we bring very deep Prototype Chain to codebase, for example – Object-&amp;gt;Array-&amp;gt;Proxy-&amp;gt;Object – then we might choose the last &lt;code&gt;.constructor.name&lt;/code&gt; as a pointer to the derived type. And for sure we might be willing additional typechecks in that case, but that is not so dead simple.&lt;/p&gt;

&lt;h1&gt;
  
  
  Pros &amp;amp; Cons
&lt;/h1&gt;

&lt;p&gt;This was an explanation of how everything works. It is small, and we may rely on it for better understanding of JavaScript structures, especially &lt;code&gt;Object&lt;/code&gt;'s derived structures. And, for sure, if we will use this understanding in a combination with other libraries, which does not provide the same level of abstraction in mind, we might fail. Or from other side we might win with distinguished explanation where they fail.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://www.npmjs.com/package/typologica"&gt;
&lt;img alt="npm" src="https://res.cloudinary.com/practicaldev/image/fetch/s--PENYLPWI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://nodei.co/npm/typologica.png%3Fmini%3Dtrue"&gt;
&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;

&lt;a href="https://coveralls.io/github/mythographica/typologica?branch=master"&gt;
&lt;img alt="Coverage Status" src="https://camo.githubusercontent.com/466101383fc674a7c4b71022d7a7218cd74de599/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d7974686f67726170686963612f7479706f6c6f676963612f62616467652e7376673f6272616e63683d6d6173746572"&gt;
&lt;/a&gt;

&lt;/td&gt;
&lt;td&gt;

&lt;img alt="Coverage Status" src="https://res.cloudinary.com/practicaldev/image/fetch/s--g6LeIUYN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/npm/l/typologica"&gt;

&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>typechek</category>
      <category>inritance</category>
    </item>
    <item>
      <title>Architecture of Prototype Inheritance in JavaScript</title>
      <dc:creator>went</dc:creator>
      <pubDate>Wed, 18 Mar 2020 00:52:56 +0000</pubDate>
      <link>https://dev.to/wentout/architecture-of-prototype-inheritance-in-javascript-ce6</link>
      <guid>https://dev.to/wentout/architecture-of-prototype-inheritance-in-javascript-ce6</guid>
      <description>&lt;p&gt;I'm stuck. Yes, I stuck. I did it the first once, then second, third and finally just ... stuck. It blows my mind, though, I think this should be coded somehow, yes. It might be the general purpose library or command line interface, whatever. It might combine the way of usage. And it is about how we code algorythms, for sure we shall live with it.&lt;/p&gt;

&lt;p&gt;For the vista of re-vision let assume it is a secret that &lt;a href="https://en.wikipedia.org/wiki/Algorithm" rel="noopener noreferrer"&gt;Algorithm&lt;/a&gt; is a "sequence" ... &lt;em&gt;of of &lt;a href="https://en.wikipedia.org/wiki/Well-defined" rel="noopener noreferrer"&gt;well-defined&lt;/a&gt;, computer-implementable instructions&lt;/em&gt; ... and so on ...&lt;/p&gt;

&lt;p&gt;And there is &lt;a href="https://en.wikipedia.org/wiki/Topological_sorting" rel="noopener noreferrer"&gt;Topological sorting&lt;/a&gt; and all the way we do instructions is a pipline of data processing.&lt;/p&gt;

&lt;p&gt;And what if there is a thing we might avoid thinking of as of a sequence? Undoubtedly from well known &lt;a href="https://en.wikipedia.org/wiki/Black_hole_information_paradox" rel="noopener noreferrer"&gt;Black hole Information Paradox&lt;/a&gt; we might probably review our understanding of "everything" as a "sequence". But from the other side there is &lt;a href="https://en.wikipedia.org/wiki/Poincar%C3%A9_conjecture" rel="noopener noreferrer"&gt;Poincaré conjecture&lt;/a&gt; and there is an impact to the solutions where we should throw out the Ideas with broken Topology.&lt;/p&gt;

&lt;p&gt;In an attempt to prepare us for the next step here is other nice &lt;strong&gt;beginner's&lt;/strong&gt; topic: &lt;a href="https://en.wikipedia.org/wiki/Composition_over_inheritance" rel="noopener noreferrer"&gt;Composition over Inheritance&lt;/a&gt;, and here is same title video from &lt;a href="https://www.youtube.com/watch?v=wfMtDGfHWpA" rel="noopener noreferrer"&gt;Fun Fun Functions&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And the hidden question there: &lt;br&gt;
&lt;strong&gt;Is Composition a Sequence or Not&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;Well... we might obviously converse it is a &lt;strong&gt;technique&lt;/strong&gt; to combine reusable sequence part of algorithms to make them work more efficiently in a whole structure.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;« &lt;a href="https://en.wikipedia.org/wiki/Stop!_(Sam_Brown_song)" rel="noopener noreferrer"&gt;But it's not that easy when your soul is torn in two&lt;/a&gt; »&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I mean, reusable parts is a great idea, all that stuff which reusably &lt;a href="https://en.wikipedia.org/wiki/Control_flow#Loops" rel="noopener noreferrer"&gt;Controls the flow&lt;/a&gt; of our code: Loops, or &lt;a href="https://en.wikipedia.org/wiki/Recursion_(computer_science)" rel="noopener noreferrer"&gt;Recursions&lt;/a&gt; or... nevermind, they are made for Greater Good. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator" rel="noopener noreferrer"&gt;Generators&lt;/a&gt; with &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" rel="noopener noreferrer"&gt;Promises&lt;/a&gt; and all that async'ish stuff are great helpers.&lt;/p&gt;

&lt;p&gt;Though when we will climb up and down on the "ladder of &lt;a href="https://en.wikipedia.org/wiki/Abstraction" rel="noopener noreferrer"&gt;abstraction&lt;/a&gt;" probably we will see the whole thing, but there might be hidden "&lt;a href="https://en.wikipedia.org/wiki/Event_horizon" rel="noopener noreferrer"&gt;black hole's event horisons&lt;/a&gt;" which we will probably hardly overcome with thinking of code "reusability".&lt;/p&gt;

&lt;p&gt;I mean "reusability" is not a thing, but "sequence" is a Thing, very natural thing with a lot of characteristics, for example "&lt;a href="https://en.wikipedia.org/wiki/State_(computer_science)" rel="noopener noreferrer"&gt;State&lt;/a&gt;" or "&lt;a href="https://en.wikipedia.org/wiki/Profiling_(computer_programming)" rel="noopener noreferrer"&gt;Observability&lt;/a&gt;" and "&lt;a href="https://en.wikipedia.org/wiki/Measurement" rel="noopener noreferrer"&gt;Measurements&lt;/a&gt;". And all this sequenced async stuff is done narrowing calculations with raw data or even with well prepared Information or odd it might be "of the bit" eventually just feelings of the kinds.&lt;/p&gt;

&lt;p&gt;Then well, when we shall connect that feelings of our mind with sequence, can we get the idea of beauty? Shold we reuse it? Or should we repeat it recursively for whatever this might be meaning then?&lt;/p&gt;

&lt;p&gt;I don't even understand what I'm writing, this might be complete noise, or one of the definitions of "&lt;a href="https://simple.wikipedia.org/wiki/42_(answer)" rel="noopener noreferrer"&gt;42&lt;/a&gt;". And indeed it is proven by &lt;a href="https://en.wikipedia.org/wiki/G%C3%B6del's_incompleteness_theorems" rel="noopener noreferrer"&gt;Gödel's incompleteness theorems&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And 42 itself is a serial number of &lt;a href="https://simple.wikipedia.org/wiki/Asterisk" rel="noopener noreferrer"&gt;multiplier&lt;/a&gt; symbol of &lt;a href="https://en.wikipedia.org/wiki/ASCI" rel="noopener noreferrer"&gt;ASCI&lt;/a&gt; symbols table, which is then connected to "&lt;a href="https://en.wikipedia.org/wiki/Per_aspera_ad_astra" rel="noopener noreferrer"&gt;...ad Astra&lt;/a&gt;" in &lt;a href="https://en.wikipedia.org/wiki/Latin" rel="noopener noreferrer"&gt;Latin&lt;/a&gt;, and then to &lt;a href="https://en.wikipedia.org/wiki/Astarte" rel="noopener noreferrer"&gt;Astarte&lt;/a&gt; or Ishtar, the godess of love, &lt;br&gt;
power and war from the Bronze Age. And she is then an avatar of &lt;a href="https://en.wikipedia.org/wiki/Sati_(Hindu_goddess)" rel="noopener noreferrer"&gt;Shakti&lt;/a&gt; or &lt;a href="https://en.wikipedia.org/wiki/Parvati" rel="noopener noreferrer"&gt;Pravati&lt;/a&gt; in &lt;a href="https://en.wikipedia.org/wiki/Hinduism" rel="noopener noreferrer"&gt;Hinduism&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And here we might think &lt;a href="https://en.wikipedia.org/wiki/Cosmos" rel="noopener noreferrer"&gt;Cosmos&lt;/a&gt; and topology and time are connected to algorythms and lifecycle of data.&lt;/p&gt;

&lt;p&gt;And what if we can combine all this flavors to a &lt;a href="https://en.wikipedia.org/wiki/Chain-of-responsibility_pattern" rel="noopener noreferrer"&gt;Chain of responsibility&lt;/a&gt; with declarative &lt;a href="https://en.wikipedia.org/wiki/Metaprogramming" rel="noopener noreferrer"&gt;Meta-programming&lt;/a&gt;?&lt;/p&gt;

&lt;p&gt;This definetely might be coded...&lt;br&gt;
We indeed can craft code allowing us to aid information retention during data lifecycle... But the question is still there: what is a Sequence? &lt;/p&gt;

&lt;p&gt;What is of that piece of minimal abstraction we should re-use avoiding of &lt;a href="https://en.wikipedia.org/wiki/Entropy_(information_theory)" rel="noopener noreferrer"&gt;Entropy&lt;/a&gt;? Where information retention is not so enough? And should that hidden piece be sacred or not?&lt;/p&gt;

&lt;p&gt;Describing algorythm as a &lt;a href="https://en.wikipedia.org/wiki/Narrative" rel="noopener noreferrer"&gt;Narrative&lt;/a&gt; story and &lt;a href="https://en.wikipedia.org/wiki/Plot_(narrative)" rel="noopener noreferrer"&gt;Plot&lt;/a&gt; we might convince then the aspect of &lt;a href="https://en.wikipedia.org/wiki/Fabula_and_syuzhet" rel="noopener noreferrer"&gt;chronological order of the events&lt;/a&gt; in the meaning of &lt;a href="https://en.wikipedia.org/wiki/Chronotope" rel="noopener noreferrer"&gt;Chronotope&lt;/a&gt; is very tightly coupled with the concept of &lt;a href="https://en.wikipedia.org/wiki/Grammatical_modifier" rel="noopener noreferrer"&gt;Grammatical modifier&lt;/a&gt; in the meaning of &lt;a href="https://en.wikipedia.org/wiki/Function_composition_(computer_science)" rel="noopener noreferrer"&gt;Function composition&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Object_composition" rel="noopener noreferrer"&gt;Object composition&lt;/a&gt; at the sequence of time.&lt;/p&gt;

&lt;p&gt;And the concept of Modifier in Software Engineering describes exactly what we are seeking for. There is a lot of them, here are just a few of may other examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;for &lt;strong&gt;Access&lt;/strong&gt;: Private, Static, Protected, Internal ...&lt;/li&gt;
&lt;li&gt;for &lt;strong&gt;Type&lt;/strong&gt;: Signed, Unsigned,  Short, Long ...&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Behaviour&lt;/strong&gt;: &lt;code&gt;'use strict';&lt;/code&gt;, "... throws" to be "thrown"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And each one of them describes an answer to the question "what will happen": so, this is a setting for Chronotope. Despite of &lt;a href="https://en.wikipedia.org/wiki/Type_system" rel="noopener noreferrer"&gt;Type Systems&lt;/a&gt; answering the question "what is it", modifiers answers the questions "how are they". So shouldn't then there be the a question "when they are",  and "why they are" and even "whose are they" in &lt;a href="https://en.wikipedia.org/wiki/Runtime_(program_lifecycle_phase)" rel="noopener noreferrer"&gt;Runtime&lt;/a&gt;?&lt;/p&gt;

&lt;p&gt;For sure, the answers are "Yes" for all that questions, it is just what we are doing as a developers. Crafting our algorythms we describe the answers to that questions, we always make:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;extracting or consuming data,&lt;/li&gt;
&lt;li&gt;transforming data from one form to the other,&lt;/li&gt;
&lt;li&gt;and then we might be storing the data or loading it somewhere else.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And seems nothing is wrong here, but... why then we have a lot of bugs everyday, isn't this is a point we might be missing something? Seems there might be some hidden review point and we shall find it for the Greater Good in a memory of the past.&lt;/p&gt;

&lt;p&gt;Indeed, then here I stuck seeking for solution.&lt;/p&gt;

&lt;p&gt;And then I remembered... It was far ago, more than 20 years, as if should it be me getting back to the past as mystic re-vision of my own future. And I got it just few month ago, obviously by a chance. To be honest it was not me who found it. I just felt it is what am I seeking for. And even more, I felt it only now, passing 20 years of seeking for nothing, being able to touch it anywhen. I can't remember that day well, it was a moment of summer obligatory computer classes after my first University term. There was a file leaved by somewone else on my clasroom's desktop with MS Windows NT. And I do remember when I saw that code I felt like complete dumb. I was unable to get the idea then, though it was clear enough, and I can describe it very well even now. There was &lt;a href="https://en.wikipedia.org/wiki/Factory_(object-oriented_programming)" rel="noopener noreferrer"&gt;Factory function&lt;/a&gt;, which was making a function and then that function returned to the variable was constructed, something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="c1"&gt;// to the glory of Mnemosyne&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Factory&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;previous&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyConstructor&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;};&lt;/span&gt;
      &lt;span class="nx"&gt;MyConstructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;previous&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;MyConstructor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;initial&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;Constructor_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Factory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;next1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Constructor_1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;Constructor_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Factory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;next1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;next2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Constructor_2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What have I missed was the &lt;code&gt;prototype&lt;/code&gt; keyword and the meaning what it was doing. There was no debugging tools that times, and I was able to understand the final &lt;code&gt;.state&lt;/code&gt; is &lt;code&gt;3&lt;/code&gt; but it was hidden from me that all  previous states are there, inside of Prototype Chain of &lt;code&gt;next1&lt;/code&gt; and &lt;code&gt;next2&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fmythographica%2Fstash%2Fmaster%2Fimg%2Finheritance.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fmythographica%2Fstash%2Fmaster%2Fimg%2Finheritance.png" alt="state of inheritance"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And inspite I noticed the name of &lt;a href="https://en.wikipedia.org/wiki/Mnemosyne" rel="noopener noreferrer"&gt;Mnemosyne&lt;/a&gt;, cause it was very close to &lt;a href="https://en.wikipedia.org/wiki/Mnemonic" rel="noopener noreferrer"&gt;Mnemonic&lt;/a&gt; and I knew this word from books of tricks and magic, I was unable to connect it with algorythm itself, thinking it was just a joke for some naughty girl.&lt;/p&gt;

&lt;p&gt;Having very few competence, undoubtedly I thought the code is just garbage, but it was indeed Genius Masterpiece...&lt;/p&gt;

</description>
      <category>inheritance</category>
      <category>architecture</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Inheritance in JavaScript : Factory of Constructors with Prototype Chain : point of view from boring nerd</title>
      <dc:creator>went</dc:creator>
      <pubDate>Tue, 25 Feb 2020 09:13:23 +0000</pubDate>
      <link>https://dev.to/wentout/inheritance-in-javascript-factory-of-constructors-with-prototype-chain-point-of-view-from-boring-nerd-2ddb</link>
      <guid>https://dev.to/wentout/inheritance-in-javascript-factory-of-constructors-with-prototype-chain-point-of-view-from-boring-nerd-2ddb</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Rof7NQq8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gguiu7k8jqsu3jf2hx5n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rof7NQq8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gguiu7k8jqsu3jf2hx5n.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hello fellow Stranger!&lt;/p&gt;

&lt;p&gt;This story is about one very special part of JavaScript, the &lt;a href="https://githut.info/"&gt;most usable&lt;/a&gt; artificial language in the world for now (2019).&lt;/p&gt;




&lt;p&gt;IMO no doubt &lt;a href="https://en.wikipedia.org/wiki/Brendan_Eich"&gt;Brendan Eich&lt;/a&gt;, the author of JavaScript programming language, is an Outstanding Genius! And this is not because he says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“ &lt;a href="https://brendaneich.com/"&gt;Always bet on JavaScript&lt;/a&gt; ”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This story is some sort of philosopher sight on Inheritance in JavaScript and my hope this vision might be based on the most relevant source of knowledge: Life itself, in it’s creatures and creations. I don’t know if it was source of vision for JavaScript Prototype Chain, though if so, this means is so impacting, so strong for me, that… it is hard to even breath…&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Let start&lt;/em&gt;&lt;/strong&gt; and our first point is where we Switch On our Imagination and try to get rid of all circumstances, prepositions and other irrelative side-effects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;We going&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://en.wikipedia.org/wiki/Back_to_the_Future"&gt;&lt;strong&gt;&lt;em&gt;back to the future&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;of early pre Internet Era of 199x.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Starting from the first &lt;a href="https://en.wikipedia.org/wiki/Hackers:_Heroes_of_the_Computer_Revolution"&gt;Hackers&lt;/a&gt; who invented everything we know of software, we then can see this Picture from the past: &lt;a href="https://en.wikipedia.org/wiki/Netscape_Navigator"&gt;Netscape Navigator&lt;/a&gt; 2 in a war run with &lt;a href="https://en.wikipedia.org/wiki/Internet_Explorer"&gt;Internet Explorer&lt;/a&gt; 3. &lt;a href="https://en.wikipedia.org/wiki/Java_%28programming_language%29"&gt;Java&lt;/a&gt; is just born and almost all, almost everything of current Internet is not yet invented and then might be re-discovered. Might also be as me you were young enough for that Good Old Times, and you can still remember this terrific feelings of how everything is crafted nearby You.&lt;/p&gt;

&lt;p&gt;So, with yous very powerful PC based on &lt;a href="https://ark.intel.com/content/www/us/en/ark/products/49966/intel-pentium-processor-with-mmx-technology-200-mhz-66-mhz-fsb.html"&gt;Intell Pentium 200 MMX™&lt;/a&gt; inside and 32Mb memory and Windows 3.11 or even Windows 95 is onboard you are looking forward. And you also have both of that &lt;a href="https://en.wikipedia.org/wiki/Web_browser"&gt;Web Browsers&lt;/a&gt; installed. &lt;a href="https://en.wikipedia.org/wiki/Dial-up_Internet_access"&gt;Dial-Up&lt;/a&gt; modem allows you to connect to the Global Network for grabbing some new data, learning, chatting and so on. However stop, no chatting throught web-pages yet, because JavaScript is still not made. Probably you use some delayed messaging systems, might be based on &lt;a href="https://en.wikipedia.org/wiki/Email"&gt;EMail&lt;/a&gt; or &lt;a href="https://en.wikipedia.org/wiki/Usenet"&gt;UseNet&lt;/a&gt; or even something like realtime communication technics with &lt;a href="https://en.wikipedia.org/wiki/Internet_Relay_Chat"&gt;IRC&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Couple of years gone, and Everything changed… Now you can see animations of snowflakes on web-pages, celebrating Christmas or New Year. And you wonder how it was done, and you able to find there is a new technology inside, called JavaScript language. &lt;a href="https://en.wikipedia.org/wiki/HTML"&gt;HTML&lt;/a&gt; is not so new for you, and you start learning that awesome and sparkling tech. Also somehow you then discover &lt;a href="https://ru.wikipedia.org/wiki/CSS"&gt;CSS&lt;/a&gt;, and this is also important, cause indeed everything is done through combining three of them together. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Wow.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And you also might see some wonderful changes for your Windows, you can now create your first application using &lt;a href="https://en.wikipedia.org/wiki/Windows_Script_Host"&gt;CScript&lt;/a&gt; or even &lt;a href="https://en.wikipedia.org/wiki/HTML_Application"&gt;HTA&lt;/a&gt; (still works).&lt;/p&gt;

&lt;p&gt;You start crafting your first Web Server, using &lt;a href="https://en.wikipedia.org/wiki/Perl"&gt;Perl&lt;/a&gt;, or &lt;a href="https://en.wikipedia.org/wiki/C_%28programming_language%29"&gt;C&lt;/a&gt;~&lt;a href="https://en.wikipedia.org/wiki/C%2B%2B"&gt;C++&lt;/a&gt;, might be even some &lt;a href="https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29"&gt;bash&lt;/a&gt; scripting if you start using &lt;a href="https://en.wikipedia.org/wiki/Unix-like"&gt;Unix-like&lt;/a&gt; &lt;a href="https://en.wikipedia.org/wiki/Operating_system"&gt;OS&lt;/a&gt;. And everything is bound between with &lt;a href="https://en.wikipedia.org/wiki/Common_Gateway_Interface"&gt;Common Gateway Interface&lt;/a&gt; (not that another &lt;a href="https://en.wikipedia.org/wiki/Computer-generated_imagery"&gt;CGI&lt;/a&gt;). &lt;a href="https://en.wikipedia.org/wiki/PHP"&gt;PHP&lt;/a&gt; is almost not exists yet, and you will probably like it then.&lt;/p&gt;

&lt;p&gt;200x Era. You can now use &lt;a href="https://en.wikipedia.org/wiki/JScript"&gt;JScript&lt;/a&gt; on server with &lt;a href="https://en.wikipedia.org/wiki/Active_Server_Pages"&gt;ASP&lt;/a&gt;. It looks like very similar to JavaScript you use for your web pages. It is so great. You think of your own &lt;a href="https://en.wikipedia.org/wiki/Template_engine"&gt;template engine&lt;/a&gt;, some sort of &lt;a href="https://en.wikipedia.org/wiki/XML"&gt;XML&lt;/a&gt;. And then someone named as &lt;a href="https://en.wikipedia.org/wiki/Ajax_%28programming%29"&gt;AJAX&lt;/a&gt; all that &lt;a href="https://en.wikipedia.org/wiki/Dynamic_HTML"&gt;Dynamic&lt;/a&gt; Content Loading techniques you’ve been using for years before. And they do only &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest"&gt;XMLHTTPRequest&lt;/a&gt; for everything, wile you can still think of &lt;a href="https://en.wikipedia.org/wiki/BMP_file_format"&gt;BMP&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe"&gt;iframe&lt;/a&gt;, or even &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script"&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;&lt;/a&gt; tag. And then someone hinted about JSON and how it very pleasant to use it, but you were using it &lt;em&gt;for ages&lt;/em&gt; in from of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;script src=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It is all not that matter &lt;strong&gt;&lt;em&gt;now&lt;/em&gt;&lt;/strong&gt;, but you still can remember &lt;strong&gt;&lt;em&gt;how&lt;/em&gt;&lt;/strong&gt;…&lt;/p&gt;

&lt;p&gt;Then from time to time you might been working with &lt;a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino"&gt;Rhino&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Nashorn_%28JavaScript_engine%29"&gt;Nashorn&lt;/a&gt; in an attempt to enjoy your Java customers who use &lt;a href="https://www.alfresco.com/"&gt;Alfresco&lt;/a&gt; or &lt;a href="https://www.asterisk.org/"&gt;Asterisk&lt;/a&gt;. You’ve heard about upcoming JS implementations on hardware chips and wonder what would it be. Also now there is &lt;a href="https://jquery.com/"&gt;jQuery&lt;/a&gt; and &lt;a href="https://backbonejs.org/"&gt;Backbone&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Then you are looking on a winter snow of upcoming 2010, and now you know there is a Game Changer number One: &lt;a href="https://nodejs.org/en/"&gt;Node.js ®&lt;/a&gt;. Next ten years you will play with this new toy, and here in 2019 you still can’t believe how great is it.&lt;/p&gt;

&lt;p&gt;In general you are enjoying all of that and toys and playing games with them is a great part of your life interests.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;But there is one small question, you ask yourself from day to day, from night to night for more than two decades:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How will you explain&lt;/strong&gt; &lt;a href="https://en.wikipedia.org/wiki/Empathy"&gt;&lt;strong&gt;Empathy&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;in JavaScript?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You know one of the hardest topics about JavaScript is of it’s &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain"&gt;Inheritance system and Prototype Chain&lt;/a&gt;. You love it, you can explain how it works, because you’ve learned it from very early moments, before the &lt;a href="https://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%201st%20edition,%20June%201997.pdf"&gt;First Standard&lt;/a&gt; was really made, and where as you remember is &lt;strong&gt;4.2.1 Objects&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ECMAScript supports prototype-based inheritance. Every constructor has an associated prototype, and &lt;strong&gt;every object created&lt;/strong&gt; &lt;strong&gt;by&lt;/strong&gt; that constructor has &lt;strong&gt;an&lt;/strong&gt; &lt;strong&gt;implicit&lt;/strong&gt; &lt;strong&gt;reference&lt;/strong&gt; to the prototype (called the object’s prototype) associated with its constructor. Furthermore, a prototype may have a non-null implicit reference to its prototype, &lt;strong&gt;and&lt;/strong&gt; so on; &lt;strong&gt;this is called the&lt;/strong&gt; &lt;strong&gt;prototype chain&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Wow… And if you, as me, indeed think this is one of the most important &lt;a href="https://en.wikipedia.org/wiki/Computer_science"&gt;CS&lt;/a&gt; inventions, then how would you explain that effect it made on you, and all the possibilities your imagination produced when you were reading it?&lt;/p&gt;

&lt;p&gt;Let’s get back again to the beginning. &lt;strong&gt;&lt;em&gt;1995 is here&lt;/em&gt;&lt;/strong&gt;. You are Brendan Eich, and you &lt;a href="https://brendaneich.com/2017/12/my-dotjs-2017-keynote/"&gt;have to invent&lt;/a&gt; new programming language. Probably you like &lt;a href="https://en.wikipedia.org/wiki/Lisp_%28programming_language%29"&gt;Lisp&lt;/a&gt; or &lt;a href="https://en.wikipedia.org/wiki/Scheme_%28programming_language%29"&gt;Scheme&lt;/a&gt;, at least in some parts. And there also is an &lt;a href="https://en.wikipedia.org/wiki/Inheritance_%28object-oriented_programming%29"&gt;Inheritance Problem&lt;/a&gt; you have to solve somehow: cause there must be some sort of &lt;a href="https://en.wikipedia.org/wiki/Object-oriented_programming"&gt;OOP&lt;/a&gt; in that new language. So &lt;em&gt;think&lt;/em&gt;: you have to mix all the things you like and might be some things you don’t like, and make this coctail Good Enough for nobody will see the difference between, until the moment there is a real reason to look inside.&lt;/p&gt;

&lt;p&gt;And now the question is again:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;how will you go with Inheritance?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let now switch back to our regular life. What all we know about Inheritance? Some obvious parts of answers to this question:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Most of all life is based on &lt;a href="https://en.wikipedia.org/wiki/Genome"&gt;Genome&lt;/a&gt;. It is a storage of data about probable creature properties and behaviour. Each one of us can infer it and own it’s part by being alive from previous life cycle generation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can make creature using two techniques: combining two predecessors or by &lt;a href="https://en.wikipedia.org/wiki/Monoicous"&gt;monocous cloning&lt;/a&gt; one of them. For sure, today you can mix some genome parts from more than two, but this is not so natural and obvious.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Time matters. If some necessary properties are not yet invented or not exists anymore, you are unable to inherit them, you can only re-create them from scratch being genome designer. And also there is a Legacy of something you own from your predecessors not through genome but by law of property, and this might be important too.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then, here we are now again, and the right question for our newly crafted language is: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Inheritance of What we have to design?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And, in any ways, we have to be able to fill the gaps between programming and life, while solving this Inheritance Problem, just because if then we will not be able to name this as an Inheritance at all.&lt;/p&gt;

&lt;p&gt;And yet one moreover: we are in 1995, using very powerful PC with only 32Mb of memory, and we trying to implement Scripting Language, so we have to take care of this memory, we have to be able to use as small amount of it as it can be possible. Each piece of data, especially &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"&gt;Strings&lt;/a&gt;, consume a lot of memory, and we have to be able to define that piece only once, and then make reference as much times as we need to have an access to our data through some techniques.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Now we can see how hard that question was.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There is a popular opinion, that “&lt;em&gt;JavaScript made of&lt;/em&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object"&gt;&lt;em&gt;Objects&lt;/em&gt;&lt;/a&gt;&lt;em&gt;”&lt;/em&gt;, so we can answer the question of what have to Inherit &lt;strong&gt;&lt;em&gt;from&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;to&lt;/em&gt;&lt;/strong&gt;: &lt;strong&gt;Objects&lt;/strong&gt;. And thinking of on that memory economy we have to store our data in Objects, also, mixing their references to data between Inherited properties of that Objects. Now we can see &lt;strong&gt;Why&lt;/strong&gt; being in 1995 &lt;strong&gt;we&lt;/strong&gt; indeed &lt;strong&gt;need&lt;/strong&gt; a design based on a prototype chain: it will help us to gain the memory economy as far as it is possible. And I think it is still the point that matters.&lt;/p&gt;

&lt;p&gt;And here we can again rely on design. Based on the opinion “&lt;em&gt;everything is an Object”&lt;/em&gt; we might be able to Clone  something. And &lt;strong&gt;&lt;em&gt;what is Cloning&lt;/em&gt;&lt;/strong&gt;? As I think, describing our requirements we might mean something like Structure Clones, or &lt;a href="https://en.wikipedia.org/wiki/Object_copying#Shallow_copy"&gt;Shallow Copies&lt;/a&gt;, or some of modern &lt;a href="http://Object.assign%28%29%20-%20JavaScript%20%7C%20MDN%20https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign"&gt;Object.assign&lt;/a&gt; ancestors. Back in 1995 we can use just structure copy, therefore we can use some of code that works with &lt;strong&gt;&lt;code&gt;for (var i in ClonedObject){}&lt;/code&gt;&lt;/strong&gt; concept for doing this, because &lt;a href="https://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%201st%20edition,%20June%201997.pdf#sec-12.6.3"&gt;it was already invented&lt;/a&gt; for the first version of standard: as you can see, this might still be working as well&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="c1"&gt;// back in 1995 cloning&lt;/span&gt;
    &lt;span class="c1"&gt;// it is not deep clone,&lt;/span&gt;
    &lt;span class="c1"&gt;// though we might not need deep at all&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;cloneProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;clonedObject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;destinationObject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;clonedObject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;destinationObject&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;clonedObject&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Also I’d recommend to take a peek &lt;a href="https://github.com/unclechu/node-deep-extend"&gt;deep-extend&lt;/a&gt; for understanding of making clones with JavaScript instead of obvious &lt;strong&gt;&lt;code&gt;for... in&lt;/code&gt;&lt;/strong&gt; implementation. Then, let’s try to imagine how using this Cloning definition sequentially, will help us to reach the following explanations of cloning pattern seems to be working in the past old ancient times:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Object from Constructor &lt;strong&gt;&lt;em&gt;cloning&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;:&lt;/em&gt; we will use Constructor for making at least two new different Clones: clone1.foo == clone2.foo
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="c1"&gt;// cloneProps is described above&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;SomeConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;clonedObject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;cloneProps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;clonedObject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;someExistingObjectToClone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;foo&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;clone1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;SomeConstructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someExistingObjectToClone&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;clone2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;SomeConstructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someExistingObjectToClone&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  Constructor from Constructor &lt;strong&gt;&lt;em&gt;cloning&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;:&lt;/em&gt; we will use one Constructor for implementing behaviour of another one Constructor: AnotherConstructor makes the same as SomeConstructor, and we don’t use cloneProps
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;SomeConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cloned&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;AnotherConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Function.prototype.call&lt;/span&gt;
      &lt;span class="c1"&gt;// was already invented in 1st ECMA-262&lt;/span&gt;
      &lt;span class="nx"&gt;SomeConstructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  Constructor from Object &lt;strong&gt;&lt;em&gt;cloning&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;:&lt;/em&gt; we will use Object for making at least two new Constructors with props cloned from that Object: calling SomeConstructor behaves the same as calling OtherConstructor
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;existentObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;foo&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;SomeConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;cloneProps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;OtherConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;cloneProps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  Object from Object &lt;strong&gt;&lt;em&gt;cloning&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;:&lt;/em&gt; we will use Object for making at least few new different Cloned Objects. So it is just &lt;strong&gt;&lt;code&gt;cloneProp(cloned, destination)&lt;/code&gt;&lt;/strong&gt; example as it’s described above.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;As we can see, cloning is obvious, it is ok, it works fine, but…&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How&lt;/strong&gt; well we will &lt;strong&gt;make an Inheritance&lt;/strong&gt; it for &lt;strong&gt;Instances&lt;/strong&gt; using &lt;strong&gt;Combinations of Predecessors&lt;/strong&gt; technique?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Inherit&lt;/em&gt;&lt;/strong&gt; Object from Constructor: as it is a Constructor Purpose itself, so this might be used as well: this is a common pattern, described everywhere
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;existentObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;foo&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;SomeConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
    &lt;span class="nx"&gt;SomeConstructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;existentObject&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;inheritedObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;SomeConstructor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// we have no instanceof yet in ECMA 262 of 1995&lt;/span&gt;
    &lt;span class="c1"&gt;// therefore we are unable to rely on this&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inheritedObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// bar&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Inherit&lt;/em&gt;&lt;/strong&gt; Constructor from Constructor. No doubt, the first who did this was genius. This is also classic example everybody knows. Here could be a much more “advanced” example, though nothing for
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;FirstConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;InheritedConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;FirstConstructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nx"&gt;InheritedConstructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;bar&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nx"&gt;InheritedConstructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;constructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;FirstConstructor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;inherited&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;InheritedConstructor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// { foo : 'bar', bar : 'foo' }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Inherit&lt;/em&gt;&lt;/strong&gt; Constructor from Object: you just rely on &lt;strong&gt;&lt;code&gt;.prototype = object&lt;/code&gt;&lt;/strong&gt; each time you make an Inheritance, therefore nothing to describe here additionally, it is always included, and any time you can change199x &lt;strong&gt;&lt;code&gt;Constructor.prototype&lt;/code&gt;&lt;/strong&gt; and it will Bubble through all of inherited Instances immediately, because memory is shared among them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Inherit&lt;/em&gt;&lt;/strong&gt; Object from Object: &lt;strong&gt;that is what it is&lt;/strong&gt;, Again! You just put any &lt;strong&gt;&lt;em&gt;Existing Object&lt;/em&gt;&lt;/strong&gt; to &lt;strong&gt;&lt;code&gt;Constructor.prototype&lt;/code&gt;&lt;/strong&gt; and after making construction calling &lt;strong&gt;&lt;code&gt;new Constructor&lt;/code&gt;&lt;/strong&gt; you will get newly &lt;strong&gt;&lt;em&gt;Inherited Instance&lt;/em&gt;&lt;/strong&gt; of that &lt;strong&gt;&lt;em&gt;Existing&lt;/em&gt;&lt;/strong&gt; prececessor &lt;strong&gt;&lt;em&gt;Object&lt;/em&gt;&lt;/strong&gt;. And, you have Explicitly put Existing Object to &lt;strong&gt;&lt;code&gt;Constructor.prototype&lt;/code&gt;&lt;/strong&gt;, only then there will be implicit reference. And only then &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof"&gt;&lt;strong&gt;instanceof&lt;/strong&gt;&lt;/a&gt;, which was initially described almost four years after Prototype Chain aroused in JS, will rely on that Constructor.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But yet one thing from Standart: &lt;strong&gt;&lt;em&gt;do this all as deep as it will be necessary&lt;/em&gt;&lt;/strong&gt; ...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;... and so on ...&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;for our inheritance&lt;/em&gt; &lt;a href="https://en.wikipedia.org/wiki/Trie"&gt;&lt;em&gt;Trie&lt;/em&gt;&lt;/a&gt;&lt;em&gt;’d prototype chain of 1995.&lt;/em&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  Let’s try make Instance &lt;strong&gt;Inheritance really deep in1995&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Indeed, let assume we have two Instances &lt;strong&gt;&lt;code&gt;{ objects }&lt;/code&gt;&lt;/strong&gt;, not the Constructors, but just plain Objects. And we wish to inherit one from another, and probably from another, and another, as the Standard says &lt;strong&gt;&lt;code&gt;and so on&lt;/code&gt;&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But How?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s look further, deeper. The right question here is, again that we noticed before: &lt;strong&gt;Inheritance of What we have to design?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We don’t need that Instances itself. We need their &lt;strong&gt;properties&lt;/strong&gt;: &lt;strong&gt;&lt;em&gt;associated data&lt;/em&gt;&lt;/strong&gt;, consuming memory; and also we need some &lt;strong&gt;behaviour&lt;/strong&gt;: &lt;strong&gt;&lt;em&gt;methods utilising that data&lt;/em&gt;&lt;/strong&gt;. It would be &lt;a href="https://en.wikipedia.org/wiki/Laissez-faire"&gt;Fair&lt;/a&gt; enough if there will also be some ability to check what from and where to we are going to Inherit. It would be also good if we can Re-Produce that design of Inheritance Pattern in future, meaning if and when we Inherit One from Another we will always get the same result, regarding to what we expect by description (contract). Though it might be also useful to fixate that creation moment somehow, cause, indeed, predecessors might change during time, and it would be not so nice we will change successor giving respect to that changes.&lt;/p&gt;

&lt;p&gt;As all of our code is a combination of data and behaviour, would it be nice that we are mixing them together utilizing that Inheritance pattern?&lt;/p&gt;

&lt;p&gt;As for me this all looks like what we see when we observe Life in all of it majestic forms. From the earlies One-Cell Creatures to their Multi-Cell Successor and then other Successors, then to the Animals… and then to &lt;a href="https://en.wikipedia.org/wiki/Homo_sapiens"&gt;humans&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Humanity_%28virtue%29"&gt;humanity&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Tribe"&gt;Tribes&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Civilization"&gt;Civilizations&lt;/a&gt; and to the &lt;a href="https://en.wikipedia.org/wiki/Intelligence"&gt;Intelligence&lt;/a&gt;, to &lt;a href="https://en.wikipedia.org/wiki/Konstantin_Tsiolkovsky"&gt;Space&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Artificial_intelligence"&gt;AI&lt;/a&gt; and going to the Galaxy, to Stars…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;and:&lt;/em&gt; &lt;br&gt;
&lt;strong&gt;“ … All we need to do is make sure we keep talking … ”&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;that incredibly mindful quote from &lt;a href="https://en.wikipedia.org/wiki/Stephen_Hawking"&gt;Stephen Hawking&lt;/a&gt; which was then popularised by &lt;a href="https://en.wikipedia.org/wiki/Pink_Floyd"&gt;Pink Floyd&lt;/a&gt;’s awesome &lt;a href="https://en.wikipedia.org/wiki/Keep_Talking"&gt;masterpiece&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And &lt;a href="https://en.wikipedia.org/wiki/Programming_language"&gt;Programming Languages&lt;/a&gt;, utilizing &lt;a href="https://en.wikipedia.org/wiki/Message_passing"&gt;Message Passing&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Flow-based_programming"&gt;Flow Based&lt;/a&gt; concepts are the Successors of that Idea. From just Raw Data we develop everything on the top of this ground level &lt;a href="https://en.wikipedia.org/wiki/Application_programming_interface"&gt;API&lt;/a&gt;. I think it is an &lt;a href="https://en.wikipedia.org/wiki/Art"&gt;Art&lt;/a&gt; as it is, and we might see as it works for JavaScript as well, deeply nested in language structure: referencing data structures through prototype chain.&lt;/p&gt;

&lt;p&gt;So, let suppose we have both Parents, they communicate (&lt;strong&gt;&lt;em&gt;keep talking&lt;/em&gt;&lt;/strong&gt;) through time, and then one moment they decide to combine their emotions and feelings together bringing a Child. And this Child then grown, meeting another grown Child, they communicate (&lt;strong&gt;&lt;em&gt;keep talking&lt;/em&gt;&lt;/strong&gt;) and deliver another child. And again and again and again, from the ancient times to exact this moment: this is the &lt;a href="https://en.wikipedia.org/wiki/Circle_of_Life"&gt;Circle of Life&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And as we can see, &lt;strong&gt;&lt;em&gt;naturally&lt;/em&gt;&lt;/strong&gt; we have to use &lt;strong&gt;&lt;em&gt;Two Parents&lt;/em&gt;&lt;/strong&gt;, no less or more, cause if we use one, it will be cloning, if we use more than two, it would be engineering: &lt;a href="https://en.wikipedia.org/wiki/Gene_Designer"&gt;Designed Genome&lt;/a&gt; of the &lt;a href="https://en.wikipedia.org/wiki/DNA"&gt;DNA&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Two creatures, not Less or More.&lt;/em&gt;&lt;/strong&gt; And they combine their properties using Inheritance, and then their children become owners of their Legacy. And each moment they combine themselves, they give us new kid. It is so simple.&lt;/p&gt;

&lt;p&gt;Sounds strange, though, yes, we have all the parts we have to have to craft Inheritance pattern in JavaScript starting from 1995. And the main part is that &lt;strong&gt;4.2.1 Objects&lt;/strong&gt;, with it’s &lt;strong&gt;implicit referencing&lt;/strong&gt; through the prototype.&lt;/p&gt;

&lt;p&gt;And this just as it is, you &lt;strong&gt;&lt;em&gt;combine Parent Object&lt;/em&gt;&lt;/strong&gt; with &lt;strong&gt;&lt;em&gt;ParentConstructor&lt;/em&gt;&lt;/strong&gt; through it’s*&lt;em&gt;&lt;em&gt;.prototype&lt;/em&gt;&lt;/em&gt;* and &lt;strong&gt;&lt;em&gt;then&lt;/em&gt;&lt;/strong&gt; this &lt;strong&gt;&lt;em&gt;Constructor&lt;/em&gt;&lt;/strong&gt; will probably make you &lt;strong&gt;&lt;em&gt;ChildObject&lt;/em&gt;&lt;/strong&gt; when you say &lt;strong&gt;&lt;em&gt;new&lt;/em&gt;&lt;/strong&gt; keyword: this is so simple, so obvious, and so terrific&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;ParentObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;foo&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;ParentConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
    &lt;span class="nx"&gt;ParentConstructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ParentObject&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;ChildObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;ParentConstructor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// starting from 1995 and then ECMA 262&lt;/span&gt;
    &lt;span class="c1"&gt;// we are able to say new&lt;/span&gt;
    &lt;span class="c1"&gt;// each time we need a ChildObject &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here we have both parents, and then the moment when we say &lt;strong&gt;new&lt;/strong&gt; we ask them to communicate. If they don’t wish to communicate process will fail with an error, and Life (js &lt;a href="https://en.wikipedia.org/wiki/Run_time_%28program_lifecycle_phase%29"&gt;runtime&lt;/a&gt; &lt;a href="https://en.wikipedia.org/wiki/Compiler"&gt;compiler&lt;/a&gt;) will say you what went wrong.&lt;/p&gt;

&lt;p&gt;And then, sure, we are asking about &lt;a href="https://en.wikipedia.org/wiki/Phylogenetic_tree"&gt;Genetic Tree&lt;/a&gt; or, which might be much more simplier about some sort of &lt;a href="https://en.wikipedia.org/wiki/Genealogy"&gt;Genealogy&lt;/a&gt;. And the answer is the same, your &lt;strong&gt;&lt;em&gt;Child Object&lt;/em&gt;&lt;/strong&gt; is grown, and &lt;strong&gt;&lt;em&gt;become Parent&lt;/em&gt;&lt;/strong&gt; Object, then met another &lt;strong&gt;&lt;em&gt;Constructor Object&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;when you say&lt;/em&gt; “new” &lt;/strong&gt; —  awesome:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="c1"&gt;// this Assignment is just to show it grew up&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;ChildObjectGrownToParent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ChildObject&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;AnotherConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
    &lt;span class="nx"&gt;AnotherConstructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ChildObjectGrownToParent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;SequentialChildObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;AnotherConstructor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="c1"&gt;// checking Life Cycle ;^)&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ChildObject&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;ParentConstructor&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;SequentialChildObject&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;ParentConstructor&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;SequentialChildObject&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;AnotherConstructor&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you combine both examples, you will see working result of Inheritance Genome. And you can continue doing this as far in deep as it would be necessary!&lt;/p&gt;

&lt;p&gt;I indeed hope this was the main Idea when design of Prototype Chain was crafted, because, as all we know this way causes some neat problems…&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;code&gt;1:&lt;/code&gt; Community …&lt;/strong&gt; As you can easily check, &lt;strong&gt;assignment&lt;/strong&gt; to*&lt;em&gt;.prototype&lt;/em&gt;* of &lt;strong&gt;&lt;em&gt;ParentConstructor&lt;/em&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;em&gt;AnotherConstructor&lt;/em&gt;&lt;/strong&gt; is a very strong S&lt;a href="https://en.wikipedia.org/wiki/Social_contract"&gt;ocial Contract&lt;/a&gt; for our Tribes, it produces references from &lt;strong&gt;&lt;em&gt;ParentObject&lt;/em&gt;&lt;/strong&gt; props (&lt;code&gt;**.foo&lt;/code&gt;** ) to the Successors: kids, &lt;strong&gt;&lt;em&gt;ChildObject&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;SequentialChildObject&lt;/em&gt;&lt;/strong&gt;. If you will change that assignment, ouch, this references will gone forever. If you will cheat and reassign this references, oops, our kids will Inherit another object props. So, when &lt;strong&gt;&lt;em&gt;combining parents with&lt;/em&gt;&lt;/strong&gt; an assignment to*&lt;em&gt;&lt;em&gt;.prototype&lt;/em&gt;&lt;/em&gt;&lt;em&gt;, probably we may tell we are going to create &lt;a href="https://en.wikipedia.org/wiki/Family"&gt;Family&lt;/a&gt;, because our parents might then produce a lot of children, and using “&lt;/em&gt;&lt;em&gt;new&lt;/em&gt;*” keyword we may ask them to deliver another one as much time as it would be necessary for our &lt;a href="https://en.wikipedia.org/wiki/User_story"&gt;Life Story&lt;/a&gt;. And then if we will destroy that.prototype based referencing we will destroy all of children properties they Inherited from the Family, such a crime drama. ;^)&lt;/p&gt;

&lt;p&gt;Therefore this all is about Legacy and we have to take care of this, if we going to build &lt;a href="https://en.wikipedia.org/wiki/Software_quality"&gt;reliable&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Maintainability"&gt;maintaineable&lt;/a&gt; code. Sure respecting &lt;a href="https://en.wikipedia.org/wiki/SOLID"&gt;S.O.L.I.D.&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Liskov_substitution_principle"&gt;Liskov substitution Principle&lt;/a&gt; with &lt;a href="https://en.wikipedia.org/wiki/Design_by_contract"&gt;Design by Contract&lt;/a&gt;, and then probably some of &lt;a href="https://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29"&gt;GRASP&lt;/a&gt; was not that problem in 1995. But it is obvious all that methodologies was not made from scratch, they were born much earlier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;2:&lt;/code&gt; Family …&lt;/strong&gt; As we can easily check, our &lt;strong&gt;&lt;em&gt;ParentObject&lt;/em&gt;&lt;/strong&gt; allowed to be very &lt;strong&gt;&lt;em&gt;frivolous&lt;/em&gt;&lt;/strong&gt; in combining itself with other Constructors. It is not fair, but we are able to use as much Constructors as we wish, Inheriting ParentObject for making other families of children. From the other side each &lt;strong&gt;&lt;em&gt;Constructor&lt;/em&gt;&lt;/strong&gt; is &lt;strong&gt;&lt;em&gt;tightly combined&lt;/em&gt;&lt;/strong&gt; with ParentObject by assignment to*&lt;em&gt;&lt;em&gt;.prototype&lt;/em&gt;&lt;/em&gt;&lt;em&gt;&lt;em&gt;.&lt;/em&gt; When we wish no harm to children we should keep that reference as long and far in time as it is possible. We might name all this as tragedy and art of our Tribe &lt;a href="https://en.wikipedia.org/wiki/History"&gt;History&lt;/a&gt;. Though also, it will protect us from &lt;a href="https://en.wikipedia.org/wiki/Amnesia"&gt;Amnesia&lt;/a&gt; of what we referenced *&lt;/em&gt;&lt;em&gt;from&lt;/em&gt;** &lt;strong&gt;&lt;em&gt;and to&lt;/em&gt;&lt;/strong&gt;, and why our children have all this &lt;a href="https://en.wikipedia.org/wiki/Legacy_code"&gt;Legacy&lt;/a&gt;. Giving a respect to &lt;a href="https://en.wikipedia.org/wiki/Mnemosyne"&gt;Mnemosyne&lt;/a&gt;, it is realy easy to &lt;a href="https://en.wikipedia.org/wiki/Software_testing"&gt;test&lt;/a&gt; our prototype chain &lt;a href="https://en.wikipedia.org/wiki/Trie"&gt;Trie&lt;/a&gt; finding &lt;a href="https://en.wikipedia.org/wiki/Artifact_%28software_development%29"&gt;Artifacts&lt;/a&gt; what we did wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;3:&lt;/code&gt; &lt;a href="https://en.wikipedia.org/wiki/Senescence"&gt;&lt;strong&gt;Senescence&lt;/strong&gt;&lt;/a&gt; …&lt;/strong&gt; Our &lt;strong&gt;&lt;em&gt;ParentObject&lt;/em&gt;&lt;/strong&gt; and our &lt;strong&gt;&lt;em&gt;Constructor&lt;/em&gt;&lt;/strong&gt; could be somehow damaged in time of our Life (runtime) is doing what it was designed for. We might keep care of what we are doing, but nowone is protected from errors. And all that changes might bring some harm to our Inheritance Successors through that prototype chain. We should keep in mind about &lt;a href="https://en.wikipedia.org/wiki/Memory_leak"&gt;Memory Leaks&lt;/a&gt;. We might be able to destroy unnecessary parts of our code. We might be able to free the memory which is no more used for our &lt;a href="https://en.wikipedia.org/wiki/Object_lifetime"&gt;Life Cycle&lt;/a&gt;. Also we should get rid of ability to bring &lt;a href="https://en.wikipedia.org/wiki/Temporal_paradox"&gt;Temporal Paradox&lt;/a&gt; to our prototype chains, though it is easy to reference Parent from Child, it might be very harmful, so we should not use that techniques of jumping from Future to Past. Finally it is possible to get full stack or pile of hardly reproducible &lt;a href="https://en.wikipedia.org/wiki/Heisenbug"&gt;Heisenbugs&lt;/a&gt; if we will try to measure something that is possible to change during time.&lt;/p&gt;




&lt;h3&gt;
  
  
  Chronicle of Solution
&lt;/h3&gt;

&lt;p&gt;It is easy, obvious and very pleasant. Instead of thinking of our Constructor as Mommy and our ParentObject as Daddy let’s try to describe them in terms of &lt;a href="https://en.wikipedia.org/wiki/Egg_cell"&gt;Egg-Cell&lt;/a&gt; and… ough… &lt;a href="https://en.wikipedia.org/wiki/Pollen"&gt;Pollen&lt;/a&gt;. So when we will make a &lt;a href="https://en.wikipedia.org/wiki/Zygote"&gt;Zygote&lt;/a&gt; using “new” keyword, then, well, there is no harm to our Imagination.&lt;/p&gt;

&lt;p&gt;Doing so, we will get rid of all that three problems. For sure then we need Egg-Cell Factory: Factory of Constructors. This might be each one of our Parents, might be Mother or Father, say as you wish, but the main point here is when we wish to say “new” we have to craft Egg-Cell and bring Pollen to it for growing up new &lt;a href="https://en.wikipedia.org/wiki/Galanthus"&gt;Galanthus flower&lt;/a&gt; in such a far and still snowing and windy Spring of 2020:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;Pollen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;season&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Spring&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="c1"&gt;// factory of constructors &lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;FlowersFactory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;proto&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;FlowerEggCell&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;};&lt;/span&gt;
      &lt;span class="nx"&gt;FlowerEggCell&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;proto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;FlowerEggCell&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;FlowerZygote&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;FlowersFactory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Pollen&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;galanthus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;FlowerZygote&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Galanthus&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That is it, now we see how it works. And don’t forget to check galanthus.season please!&lt;/p&gt;

&lt;p&gt;For sure, &lt;a href="https://en.wikipedia.org/wiki/Cyclomatic_complexity"&gt;Cyclomatic Complexity&lt;/a&gt; of solutions you will do utilizing this pattern is absolutely outstanding and as for me they can be compared with something you see solving &lt;a href="https://en.wikipedia.org/wiki/Zebra_Puzzle"&gt;Zebra Puzzle&lt;/a&gt;. Therefore I made a &lt;a href="https://www.npmjs.com/package/mnemonica"&gt;&lt;strong&gt;&lt;em&gt;library&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;, which might help with constructors &lt;a href="https://en.wikipedia.org/wiki/Method_chaining"&gt;chaining&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Memoization"&gt;memoization&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I can’t prove it, but this technique is successfully used for two decades from time to time when you need to be sure you did the best with Inheritance. As you can check it is more than testable, reproducible and maintainable. Didn’t telling the whole story here, we just rely on fact: JavaScript designed &lt;em&gt;enough&lt;/em&gt; &lt;em&gt;good&lt;/em&gt; even for making Genealogy Trie with Inheritance. Also we didn’t discuss the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes"&gt;Class&lt;/a&gt; degradation, but you can easily implement &lt;strong&gt;&lt;em&gt;FlowerEggCellClass&lt;/em&gt;&lt;/strong&gt; instead of just &lt;strong&gt;&lt;em&gt;FlowerEggCell&lt;/em&gt;&lt;/strong&gt; inside of &lt;strong&gt;&lt;em&gt;FlowersFactory&lt;/em&gt;&lt;/strong&gt;. The main part here is as it is, if you will wish to use &lt;strong&gt;&lt;em&gt;instanceof&lt;/em&gt;&lt;/strong&gt; checking for your flowers you will see they all are made from that &lt;strong&gt;&lt;em&gt;FlowerEggCell&lt;/em&gt;&lt;/strong&gt; constructors you referenced through &lt;strong&gt;&lt;em&gt;FlowerZygote&lt;/em&gt;&lt;/strong&gt;. And, for sure, you can change &lt;strong&gt;&lt;em&gt;FlowerZygote&lt;/em&gt;&lt;/strong&gt; in time, it will bring no harm for &lt;strong&gt;&lt;em&gt;FlowersFactory&lt;/em&gt;&lt;/strong&gt;, it will continue be able to produce new “&lt;a href="https://en.wikipedia.org/wiki/Reference_design"&gt;referenced&lt;/a&gt;” constructors in future according to the design you did.&lt;/p&gt;

&lt;p&gt;My hope this article will reveal all uncertainty with how important &lt;strong&gt;.prototype&lt;/strong&gt; keyword is, and then seeing usage of &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null"&gt;&lt;strong&gt;&lt;code&gt;null&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt; in place of &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this"&gt;&lt;strong&gt;&lt;code&gt;this&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt; for &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind"&gt;&lt;strong&gt;&lt;code&gt;.bind(null, ...&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt; or &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/call"&gt;&lt;strong&gt;&lt;code&gt;.call(null, ...&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt; or &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/apply"&gt;&lt;strong&gt;&lt;code&gt;.apply(null, ...&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt; you will feel &lt;a href="https://en.wikipedia.org/wiki/Sorrow_%28Pink_Floyd_song%29"&gt;Sorrow&lt;/a&gt; about current &lt;a href="https://en.wikipedia.org/wiki/Blueprint"&gt;design state&lt;/a&gt; of the code style they made.&lt;/p&gt;

&lt;p&gt;Thank You for reading this!&lt;/p&gt;

&lt;p&gt;All in good time!&lt;/p&gt;

&lt;p&gt;Sincerely yours V&lt;/p&gt;

&lt;p&gt;PS 1:&lt;br&gt;
&lt;a href="https://habr.com/ru/post/470994/"&gt;RU version&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PS 2:&lt;br&gt;
Exported from &lt;a href="https://medium.com"&gt;Medium&lt;/a&gt; on February 25, 2020.&lt;br&gt;
&lt;a href="https://medium.com/@went.out/javascript-prototype-inheritance-point-of-view-from-boring-nerd-9c7924afc9fc"&gt;Canonical link&lt;/a&gt; on October 9, 2019.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>inheritance</category>
      <category>prototype</category>
    </item>
  </channel>
</rss>
