<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mani Bollu on Medium]]></title>
        <description><![CDATA[Stories by Mani Bollu on Medium]]></description>
        <link>https://medium.com/@manibollu?source=rss-a92350e41427------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Yz_FYh9mW96RRP7R.</url>
            <title>Stories by Mani Bollu on Medium</title>
            <link>https://medium.com/@manibollu?source=rss-a92350e41427------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 17:57:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manibollu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Make sure you understand DOM before jumping into JS frameworks]]></title>
            <link>https://medium.com/@manibollu/understand-dom-before-jumping-into-js-frameworks-29dc87a6788d?source=rss-a92350e41427------2</link>
            <guid isPermaLink="false">https://medium.com/p/29dc87a6788d</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[understanding]]></category>
            <category><![CDATA[document-object-model]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mani Bollu]]></dc:creator>
            <pubDate>Thu, 26 Jan 2023 04:51:16 GMT</pubDate>
            <atom:updated>2023-01-26T04:51:16.743Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why prototypes are more fun than classes, re-discover the glory of Javascript — ES5</h3><p>This article might be trivial to most JS developers out there. But, ask yourself a couple of questions:</p><p><strong><em>1. How you learnt Javascript in first place?</em></strong></p><p>Like me, if you also are/were a backend developer who learnt javascript in a hurry, just to enhance your view components, you must be happy thinking that Javascript is a pretty simple programming language which brings the HTML elements into DOMs and gives you an enormous control over them. And Jquery takes it a level higher.</p><p><strong><em>2. What exactly DOM means, what is its hierarchy, what are its components, difference between DOM properties and HTML attributes?</em></strong></p><p>Not sure.</p><p>If you’ve similar answers to the above questions, you may find this article interesting and useful.</p><p>With the evolution of Node and various JS frameworks, it is time to forget Jquery and write more professional and maintainable code. While learning modern JS frameworks such as Angular 2, we can easily run into issues and a series of misunderstandings if we don’t have a proper knowledge on the underlying concepts of Javascript.</p><p>It all started a couple of years ago when me and my friend had an argument over classes in Javascript (ES5). My friend said there are no classes in Javascript, but I was pretty sure that he is wrong as I could see objects and inheritance in Javascript.</p><pre>var object = new Object()</pre><p>So, there should be classes in Javascript (ES5)… isn’t it?</p><p>For the sake of fact, my friend was right when he said there are no classes in Javascript (ES5). But, how about the piece of code which I was referring to? Yes, Javascript (ES5) is an object-oriented programming language but it’s not a Class-based one, instead it is a Prototype-based language.</p><p><strong>But, what is a prototype?</strong></p><p>Unlike a traditional class-based language, every function in Javascript implicitly has a property called <strong><em>prototype</em></strong>. Prototype is a Javascript object {} which contains a <em>constructor</em> property. This constructor property points to the original function itself.</p><p>I know this is getting little weird, but this is how Javascript designed. For example:</p><pre>function simpleFunction() {<br>   var a = 100,<br>       b = 200;<br>}</pre><pre>simpleFunction.prototype;<br>&gt; <em>Object {constructor: function, __proto__: Object}</em></pre><pre>simpleFunction.prototype.constructor;<br><em>&gt; function simpleFunction() {<br>     var a = 100,<br>         b = 200,<br>  }</em></pre><pre>simpleFunction.prototype.constructor.prototype;<br>&gt; <em>Object {constructor: function, __proto__: Object}</em></pre><pre>// so, the function assigned to constructor property is nothing but the original function which we defined. If you find it interesting, you should play with a simple function definition in your browser&#39;s console.</pre><p>That’s fair enough, BUT (a big one), what about the other property in the prototype object i.e. __proto__ : Object ?</p><p>Now, with that question in mind, it’s time for us to get into the inheritance in Javascript. Every object {} is inherited from another object. If we don’t define an explicit inheritance, it will be derived from Object object of Javascript:</p><pre>var simpleObject = {};</pre><pre>simpleObject;<br>&gt; {__proto__:Object}</pre><p>To explain the implementation of objects and their inheritance in Javascript (ES5), I’d like to use a simple insurance hierarchy example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0cSVgbofHTCnyRmp5BlGDw.png" /><figcaption>Simple insurance hierarchy — created using <a href="http://draw.io/">draw.io</a></figcaption></figure><p>To keep it simple, let’s start with Java first…</p><p><strong>In Java:</strong></p><pre>public class Insurance {<br>   public int premium;<br>   public int coverage;<br>   <br>   Insurance(premium, coverage) {<br>      this.premium = premium;<br>      this.coverage = coverage;<br>   }<br>   <br>   public float coverageByPremium() {<br>      return coverage/premium;<br>   }<br>}</pre><pre>Insurance insurance = new Insurance(2000, 2000000);</pre><pre>System.out.println(insurance.premium);<br>// 2000<br>System.out.println(insurance.coverage);<br>// 2000000</pre><p>It’s pretty straight forward. If you don’t understand what was happening in the above snippet, I recommend you to stop reading this article immediately and look at <a href="http://www.deitel.com/Books/Java/JavaforProgrammers/tabid/3416/Default.aspx">Java for programmers (Deitel Developer)</a> or <a href="https://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias%3Dstripbooks&amp;field-keywords=Javascript+book">JavaScript and JQuery: Interactive Front-End Web Development</a> (If you want to learn prototype programming directly).</p><p><strong>In Javascript (ES5):</strong></p><p>In ES5, there are several ways to define an Object. For this example, I would choose to write a constructor function to create my Insurance object.</p><pre>function Insurance(premium, coverage) {<br>   this.premium = premium;<br>   this.coverage = coverage;</pre><pre>   this.coverageByPremium = function() {<br>      return (this.coverage/this.premium)<br>   }<br>}</pre><pre>var insurance = new Insurance(2000, 2000000);</pre><pre>console.log(insurance.premium);<br>// 2000<br>console.log(insurance.coverage);<br>// 2000000</pre><pre>// notice &quot;this.premium&quot; and &quot;this.coverage&quot; as they are different from the variables which we are passing to the function i.e. premium, coverage. </pre><p>As you’d have already noticed, it looks pretty similar to a class-based language. Also a good number of JS developers simply refer to constructor functions as classes. Of course, it’s not illegal, but causes more confusion especially when you have a Java or similar background.</p><p>Alternate method to define Object in ES5, but we will stick on to the above method as we proceed further…</p><pre>var Insurance = {<br>   premium: 0,<br>   coverage: 0<br>   coverageByPremium: function() {<br>      return (this.coverage/this.premium)<br>   }<br>}</pre><pre>var insurance = Object.create(Insurance);</pre><pre>insurance.premium = 2000;<br>console.log(insurance.premium);<br>// 2000<br>console.log(insurance.coverage);<br>// 0</pre><pre>// As you may have noticed, we have just created a pure JS object (JSON style) rather than a constructor function. Since there&#39;s no constructor in place, we haven&#39;t set values to properties during initialization. </pre><pre>But, we can do that by sending an extra object to &quot;Object.create&quot;.</pre><pre>Example:<br>var insurance = Object.create(Insurance, {premium: 2000, coverage: 2000000}); </pre><pre>Please refer to <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create">Object.create</a> doc for full details on its usage.</pre><p><strong>Inheritance:</strong></p><p>Now, we have “Life insurance” and “Property &amp; Casualty insurance” inheriting from the our master class/object “Insurance”. Let’s implement this in both JS as well as Java.</p><p><strong>In Javascript (ES5):</strong></p><pre>function AutoInsurance(model, mileage, noOfOwners, antiTheftDevice, premium, coverage) {<br>   Insurance.call(this, premium, coverage);<br>   this.model = model; <br>   this.mileage = mileage; <br>   this.noOfOwners = noOfOwners; <br>   this.antiTheftDevice = antiTheftDevice;<br>}</pre><pre>AutoInsurance.prototype = new Insurance();</pre><pre>var autoInsurance = new AutoInsurance(3000000);</pre><pre>console.log(autoInsurance.propertyValue);<br>// 3000000<br>console.log(autoInsurance.premium);<br>// 3000<br>console.log(autoInsurance.coverageByPremium);<br>// 1000</pre><p><strong>In Java:</strong></p><pre>public class PCInsurance extends Insurance {<br>   public int propertyValue;<br>   <br>   PCInsurance(propertyValue) {<br>      super(3000,propertyValue);<br>      this.propertyValue = propertyValue;<br>   }<br>}</pre><pre>Insurance insurance = new Insurance(2000, 2000000);</pre><pre>System.out.println(insurance.premium);<br>// 2000<br>System.out.println(insurance.coverage);<br>// 2000000</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29dc87a6788d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>