<?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 Francis Pham on Medium]]></title>
        <description><![CDATA[Stories by Francis Pham on Medium]]></description>
        <link>https://medium.com/@franpham?source=rss-7dacf21d9917------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*V_pEqwZo_VD-75c9.jpg</url>
            <title>Stories by Francis Pham on Medium</title>
            <link>https://medium.com/@franpham?source=rss-7dacf21d9917------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:32:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@franpham/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Coming Homes Tsunami]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://franpham.medium.com/the-coming-homes-tsunami-f3d7aae37dc3?source=rss-7dacf21d9917------2"><img src="https://cdn-images-1.medium.com/max/700/1*WDUbLJTybLPtflj1XdPRPw.jpeg" width="700"></a></p><p class="medium-feed-snippet">The real estate market has become like shopping for toilet paper &amp; Purell when Covid-19 lockdowns first began in March, 2020. Buyers are&#x2026;</p><p class="medium-feed-link"><a href="https://franpham.medium.com/the-coming-homes-tsunami-f3d7aae37dc3?source=rss-7dacf21d9917------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://franpham.medium.com/the-coming-homes-tsunami-f3d7aae37dc3?source=rss-7dacf21d9917------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3d7aae37dc3</guid>
            <category><![CDATA[real-estate]]></category>
            <category><![CDATA[home]]></category>
            <category><![CDATA[homes-for-sale]]></category>
            <category><![CDATA[bay-area-housing]]></category>
            <category><![CDATA[bay-area]]></category>
            <dc:creator><![CDATA[Francis Pham]]></dc:creator>
            <pubDate>Sat, 03 Apr 2021 03:40:48 GMT</pubDate>
            <atom:updated>2021-04-26T18:07:05.891Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Finding the Ideal E-Bike: Motors Comparison]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://franpham.medium.com/finding-the-ideal-e-bike-motor-c18caeb52ae?source=rss-7dacf21d9917------2"><img src="https://cdn-images-1.medium.com/max/1100/1*9OM7qsF8zRDzNqKgMxMtrQ.jpeg" width="1100"></a></p><p class="medium-feed-snippet">support level, which is power output for the amount of work you put in. Equal torque does not mean equal support level due to the&#x2026;</p><p class="medium-feed-link"><a href="https://franpham.medium.com/finding-the-ideal-e-bike-motor-c18caeb52ae?source=rss-7dacf21d9917------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://franpham.medium.com/finding-the-ideal-e-bike-motor-c18caeb52ae?source=rss-7dacf21d9917------2</link>
            <guid isPermaLink="false">https://medium.com/p/c18caeb52ae</guid>
            <category><![CDATA[specialized]]></category>
            <category><![CDATA[bafang]]></category>
            <category><![CDATA[ebike]]></category>
            <category><![CDATA[shimano]]></category>
            <category><![CDATA[bosch]]></category>
            <dc:creator><![CDATA[Francis Pham]]></dc:creator>
            <pubDate>Sat, 20 Jul 2019 02:42:19 GMT</pubDate>
            <atom:updated>2020-11-03T03:04:06.113Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[E-Bike Guide: gauging motor torque & battery]]></title>
            <link>https://franpham.medium.com/e-bike-guide-choosing-the-right-motor-battery-ebd4010b13f3?source=rss-7dacf21d9917------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebd4010b13f3</guid>
            <category><![CDATA[road-biking]]></category>
            <category><![CDATA[ebike]]></category>
            <category><![CDATA[mountain-bike]]></category>
            <category><![CDATA[biketouring]]></category>
            <category><![CDATA[bikes]]></category>
            <dc:creator><![CDATA[Francis Pham]]></dc:creator>
            <pubDate>Tue, 04 Jun 2019 23:22:26 GMT</pubDate>
            <atom:updated>2020-07-25T02:26:12.755Z</atom:updated>
            <content:encoded><![CDATA[<h3>E-Bike Guide: Ideal Motor &amp; Battery</h3><p>When you are deciding which E-bike will elevate your riding experience, you will face questions about the bike’s range and power. Similar to electric car drivers, E-bike riders can have range anxiety; no one wants to be stuck with a 25+ kg. bike on a mountain when the sun is setting. Many trails have steep hills at 25’+ degrees inclines; you may develop climb anxiety because you’re literally tired of not being able to climb those hills without stopping and pushing your bike. Several thousands euros is a big purchase so you don’t want to make a bad decision, but you may not have any experience with e-bikes and there is limited info about the subjects. After reading this article, you will have a concrete guide for how strong the motor and battery should be, considering your weight, your age, time biking, distance travelled, and motor output. While having the right battery and motor will help your ride significantly, those two factors are only one part of an ideal bike. You must consider the bike geometry (ie: how it fits you and rides) and the bike components (ie: brakes, shocks, shifters, etc). This article does not address those issues, but helps you solve part of the bike search.</p><p>Your weight affects how strong the motor needs to be; the heavier you are, the more power is needed to move. Reality sets in as you get older and you realize you are not as strong as you were in your 20’s. Thus, your age must be accounted for when calculating the motor strength, which in turn affects the battery capacity. The duration of the bike ride, excluding time stopped, affects how much battery capacity you will need. Similarly, the length of the bike ride will proportionally increase the required capacity of the battery. However, less battery strength is needed for more efficient motors. The support level, which is the power output for the amount of work put in, determines the motor efficiency that is used in the battery equation. With these factors accounted for, you can determine the necessary battery capacity and motor torque needed for your new E-MTB.</p><p>Other minor factors affect the battery capacity, but they are not included in our equation because either they are subjective to the rider or hard to quantify. Too high or too low outdoor temperature (below 45&#39;F or above 90&#39;F) prevents the battery from operating at its optimal efficiency, which reduces your possible range/ climb. Too low tire pressure can increase your rolling resistance, which increases the motor’s energy usage and reduce your range/ climb. E-bike motors have different cadences that give peak efficiency (typically 60–90 rpm); riding your bike at the peak cadence will prolong the battery and increase your range/ climb. Finally, the terrain and riding style will affect the duration of the battery; accelerating often or steeper slopes needs more energy, which reduces your range/ climb. To increase the distance or climb of the ride without increasing the battery capacity, the operating efficiency needs to be increased. You can achieve this by either reducing your weight (self, bike, gear, etc) to reduce the motor’s load or ride in cooler temperature to decrease the energy loss from heat production. You can expect an increase in distance or climb that is proportional to the reduction in total weight or outdoor temperature. For example, a decrease of 25% in total weight from 120 kg to 90 kg or a decrease of temperature from 90’F to 68’F would result in a proportional increase of 25% (tested) in either distance or climb that can be ridden.</p><p>For road bikes, the difference in fitness factor is minimal since rolling resistance is much less and riding momentum is easier to maintain. The needed battery capacity for road bikes is determined by climb and age since the distance cancels out in the equation. For the same reasons, the torque needed for road bikes is less. These equations were tested on rides like the road around Lake Tahoe in California (Tour de Tahoe), which is 73 miles and 4000+ feet.</p><p>In the examples, we assume typical body and bike weights for a range of ages (older age = higher income = lighter bike &amp; stronger motor, but less endurance &amp; heavier person). We assume the rider uses an assistance level proportional to the grade of the climb. Generally, a 50Nm motor should provide 200% support level and every 10Nm more gives you another 50% support. The recommended battery assumes 10% remaining capacity for emergencies and to prolong the battery life. These equations were formulated based on riding an e-mtb on 50+ trails for over 1000 miles and climbing over 150,000 feet. Regardless of your age or riding distance, there is always a motor and battery that will fit your needs.</p><blockquote><strong>MTB Battery, Wh = </strong>[meters climb + (hr time * km distance * years over 25)] <strong>/ </strong>(fitness factor * motor efficiency)</blockquote><blockquote><strong>MTB Torque, Nm =</strong> kg self weight+ kg bike weight — (1.62 * years &lt; 55)</blockquote><blockquote><strong>Road Battery =</strong> climb % * km dist. * age / hr time * 4 = age * 25 * km climb / hr time</blockquote><blockquote><strong>Road Torque, Nm =</strong> (kg self weight+ kg bike weight — years &lt; 55) / 1.62</blockquote><blockquote>Climb Grade = 100 * km climb / km distance; Efficiency = support level/ 100</blockquote><p><strong>Fitness factor:</strong> use 2 if athletic, 1.62 if fit, or 1.4 if weak or heavy. Fit means exercise 4 hours per week; use 1 for “years &gt; 25” if 25 or under; use 0 for “years &lt; 55” if 55 or above. 1.62 (rounded up from 1.618) is known as the golden ratio, which occurs often in nature.</p><p><strong>MTB Recommendation:</strong> 60–120 Nm providing 240–540% support</p><p><strong>Road Recommendation:</strong> 40–80 Nm providing 160-360% support</p><p><strong>For quick estimates</strong> while you’re shopping:</p><blockquote>MTB Battery, Wh = Age * 15</blockquote><blockquote>MTB Torque, Nm = Age * 2</blockquote><blockquote>Road Battery, Wh = Age * 8</blockquote><blockquote>Road Torque, Nm = Age * 1.5</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q_VMI367DgM0bh5t8B_-Qg.png" /><figcaption>Motors &amp; Batteries Requirements</figcaption></figure><p><a href="https://medium.com/@franpham/finding-the-ideal-e-bike-motor-c18caeb52ae">Finding the Ideal E-Bike: Motors Comparison</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9OM7qsF8zRDzNqKgMxMtrQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebd4010b13f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coding Bootcamp Guide: how to avoid scams & empty promises]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://franpham.medium.com/coding-bootcamp-guide-get-skilled-not-drilled-7440fc4cb3a5?source=rss-7dacf21d9917------2"><img src="https://cdn-images-1.medium.com/max/1000/1*cymqkeeArNRaSC5ic9s2mQ.jpeg" width="1000"></a></p><p class="medium-feed-snippet">10 criteria: There&#x2019;s a lot of demand for software developers with skills in the latest technologies. These companies, usually small to&#x2026;</p><p class="medium-feed-link"><a href="https://franpham.medium.com/coding-bootcamp-guide-get-skilled-not-drilled-7440fc4cb3a5?source=rss-7dacf21d9917------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://franpham.medium.com/coding-bootcamp-guide-get-skilled-not-drilled-7440fc4cb3a5?source=rss-7dacf21d9917------2</link>
            <guid isPermaLink="false">https://medium.com/p/7440fc4cb3a5</guid>
            <category><![CDATA[online-education]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Francis Pham]]></dc:creator>
            <pubDate>Sat, 20 Feb 2016 01:57:54 GMT</pubDate>
            <atom:updated>2019-06-05T22:31:18.771Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[SQL vs. NoSQL Databases & Properties]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://franpham.medium.com/sql-vs-nosql-databases-properties-e07fd89ac9bf?source=rss-7dacf21d9917------2"><img src="https://cdn-images-1.medium.com/max/966/1*6thPvnJs8cCj72oEy4EBfg.jpeg" width="966"></a></p><p class="medium-feed-snippet">NoSql databases have been increasing in popularity, so let&#x2019;s layout the differences between SQL and NoSql, and why you would choose one&#x2026;</p><p class="medium-feed-link"><a href="https://franpham.medium.com/sql-vs-nosql-databases-properties-e07fd89ac9bf?source=rss-7dacf21d9917------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://franpham.medium.com/sql-vs-nosql-databases-properties-e07fd89ac9bf?source=rss-7dacf21d9917------2</link>
            <guid isPermaLink="false">https://medium.com/p/e07fd89ac9bf</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[nosql]]></category>
            <dc:creator><![CDATA[Francis Pham]]></dc:creator>
            <pubDate>Fri, 23 Oct 2015 21:25:23 GMT</pubDate>
            <atom:updated>2019-06-04T23:58:46.215Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[javascript.eval(object.prototype)]]></title>
            <link>https://franpham.medium.com/javascript-eval-object-prototype-b09e5af06255?source=rss-7dacf21d9917------2</link>
            <guid isPermaLink="false">https://medium.com/p/b09e5af06255</guid>
            <category><![CDATA[prototype]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Francis Pham]]></dc:creator>
            <pubDate>Sat, 19 Sep 2015 21:37:23 GMT</pubDate>
            <atom:updated>2015-09-19T21:37:23.850Z</atom:updated>
            <content:encoded><![CDATA[<p>A <strong>prototype</strong> is a singleton object for each class that: contains the current class’ methods, has a public reference (.constructor) to the constructor function to make objects of the current class, and a private reference (passed in at Object.create) to the superclass’ prototype. Since <strong>prototype</strong> is a Class property, the instance property is __proto__, but getPrototypeOf should be used:</p><p>Class.prototype === [[prototype]] === Object.getPrototypeOf(obj) === obj.__proto__</p><p><strong>prototype.constructor</strong> is the Function that creates objects of the current class. The base object is Object, which does not have a prototype.</p><p><strong>IMPORTANT</strong>: if the object is an instance, call Object.getPrototypeOf(obj) to get the prototype, NOT instance.prototype since prototype is a CLASS property; instance.__proto__ is possible, but it’s much slower &amp; not recommended.</p><p>Instance properties or methods will override the prototype’s properties or methods of the same name because the constructor bindings occur AFTER the prototype bindings.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b09e5af06255" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Recursion to implement Reflection in Javascript]]></title>
            <link>https://franpham.medium.com/using-recursion-to-implement-reflection-in-javascript-63b1bd981546?source=rss-7dacf21d9917------2</link>
            <guid isPermaLink="false">https://medium.com/p/63b1bd981546</guid>
            <category><![CDATA[recursion]]></category>
            <category><![CDATA[reflections]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Francis Pham]]></dc:creator>
            <pubDate>Wed, 16 Sep 2015 20:10:03 GMT</pubDate>
            <atom:updated>2015-09-16T21:13:39.648Z</atom:updated>
            <content:encoded><![CDATA[<p>Many CS languages have reflection built in, but javascript only has limited functionality to reflect on its code. Reflection is the ability to provide to the programmer useful info about any code, like a function or class. To reflect a class, you would need to output the methods and properties that each class implements. Since classes’ prototypes are chained, using recursion is ideal to solve this problem. Implementing reflection for prototypes is relatively easy: the function should call Object.keys() to get the current class’ properties and recursively call itself until the base case is reached, which is when getPrototypeOf(prototype) is null.</p><p>This website doesn’t allow multiple spacing/ tabs, so see <a href="http://jsbin.com/xozuzeyozu/edit?js">jsbin.com for the formatted code</a>.</p><p>function reflector(obj) {</p><p>if (Object.getPrototypeOf(obj) !== null) { // the recursive base case is Object, whose prototype is null;</p><p>reflector(Object.getPrototypeOf(obj));</p><p>}</p><p>console.log(‘Class: ‘ + obj.constructor.name);</p><p>// get the properties in the current prototype;</p><p>console.log(‘prototype properties: ‘ + Object.keys(obj));</p><p>}</p><p>However, this only gets the public properties defined on the class prototype. To get the privileged and instance methods defined in the constructor, the problem gets more complicated since Object.keys() gives all privileged/ instance methods regardless if they’re defined in the current class or a superclass. You may wonder why Object.keys() is climbing the inheritance tree when the documentation says it doesn’t. Actually, that function is still only looking at the current class because all privileged &amp; instance methods are assigned to EACH instance, not to the instances’ class prototype, regardless of where those methods are defined. So to get the privileged &amp; instance methods, one must compare the methods of an INSTANCE of the current class to those methods of an INSTANCE of the super class.</p><p>function reflector(obj) {</p><p>if (obj instanceof obj.constructor) { // if obj is an instance, call reflector with its prototype without printing;</p><p>reflector(Object.getPrototypeOf(obj));</p><p>} else {</p><p>var theseKeys;</p><p>if (Object.getPrototypeOf(obj) !== null) {</p><blockquote>var superKeys = reflector(Object.getPrototypeOf(obj));</blockquote><blockquote>// if prototype is not null (aka: obj is not Object), recursively call reflector;</blockquote><blockquote>// UNROLL: use return values of later recursions to compare Subclass’ properties with the Superclass’ properties;</blockquote><blockquote>var diffKeys = Object.keys(new obj.constructor());</blockquote><blockquote>diffKeys = diffKeys.filter(function(val) { return !superKeys.some(function(sup) { return sup === val; });</blockquote><blockquote>});</blockquote><blockquote>console.log(‘Class: ‘ + obj.constructor.name);</blockquote><blockquote>console.log(‘instance properties: ‘ + diffKeys);</blockquote><blockquote>theseKeys = Object.keys(obj);</blockquote><p>} else { // the recursive base case is Object, whose prototype is null;</p><blockquote>console.log(‘Class: ‘ + obj.constructor.name);</blockquote><blockquote>theseKeys = Object.getOwnPropertyNames(Object.prototype);</blockquote><p>}</p><p>console.log(‘prototype properties: ‘ + theseKeys);</p><p>return Object.keys(new obj.constructor());</p><p>}</p><p>}</p><p>Javascript provides 3 functions to iterate through the properties of an object. Object.keys() gets the enumerable properties of the current class only. The for … in loop gets the enumerable properties in the current class AND in it’s prototype chain. The Object.getOwnPropertyNames gets both enumerable &amp; non-enumerable properties in the current class only. See the MDN page for more info on property enumerability and ownership: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties</a></p><p>Now with this reflector function, you can reflect on the public &amp; inherited properties of an object’s prototype and the privileged &amp; instance properties of an object instance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63b1bd981546" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Infinite loops in ES6 Classes: pinky key to the rescue!]]></title>
            <link>https://franpham.medium.com/infinite-loops-in-es6-classes-pinky-key-to-the-rescue-fe1d28b77a52?source=rss-7dacf21d9917------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe1d28b77a52</guid>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[object-oriented]]></category>
            <dc:creator><![CDATA[Francis Pham]]></dc:creator>
            <pubDate>Wed, 16 Sep 2015 02:02:48 GMT</pubDate>
            <atom:updated>2015-09-16T02:02:48.095Z</atom:updated>
            <content:encoded><![CDATA[<p>Who woulda thunk the underscore key ‘_’ can help prevent an infinite loop when using classes in ES6?</p><p>ES6 enables getter &amp; setter methods for classes. However in ES6, the properties’ names must NOT be the same as the method names. Note that in ES5, the properties’ names and method names can be the same, although you may not get the behavior that you want. The reason why naming matters is because of the way ES6 implements getting &amp; setting properties.</p><p>For example, assume you have a guy object created from the Person class in ES6 with a name property. If you have both a property called name and method called name, then an infinite loop will occur because instead of getting or setting the properties directly like an object literal (guy.name), ES6 actually CALLS the getter/ setter methods instead (guy.name()). The exact error message ES6 will give you is “maximum stack calls exceeded”.</p><p>class Person { // ES6 example</p><p>constructor(name) {</p><p>this.name = name;</p><p>}</p><p>get name() {</p><p>return this.name;</p><p>} // since ES6 calls name() for this.name, an infinite loop will occur;</p><p>}</p><p>function Person(name) { // ES5 example</p><p>this.name = name;</p><p>}</p><p>Person.prototype.name = function() {</p><p>return this.name;</p><p>}; // in ES5, since name property is defined in Person class, the name function in the prototype is never called; a TypeError (not a function) is thrown if name() is called</p><p>A conventional solution to prevent the infinite loop in ES6 is to simply prefix the property name by ‘_’. Although the ‘_’ character typically implies a private property, this.property is NOT private for classes in ES6; instead properties are public in ES6 by default. This is why I originally did not use ‘_’ to prefix properties and ran into the infinite loop that took me an hour to debug! So just use the ‘_’ or some other character to prefix property names to prevent infinite loops when using classes in ES6.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe1d28b77a52" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Class Usage & Inheritance: 3 ways to inherit]]></title>
            <link>https://franpham.medium.com/class-usage-inheritance-3-ways-to-inherit-3062caca39b3?source=rss-7dacf21d9917------2</link>
            <guid isPermaLink="false">https://medium.com/p/3062caca39b3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[class-inheritance]]></category>
            <dc:creator><![CDATA[Francis Pham]]></dc:creator>
            <pubDate>Fri, 11 Sep 2015 04:21:02 GMT</pubDate>
            <atom:updated>2015-09-11T22:39:59.268Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>There are 3 ways to extends a superclass:</strong></p><p>1. For ES6, declare: <strong>class</strong> Subclass <strong>extends</strong> Superclass</p><p>example: class Mammal extends Animal { … }</p><p>2. For ES5, create an object based on the superclass prototype and set the subclass prototype’s constructor to the subclass’ FUNCTION:</p><p>Subclass.prototype = Object.create(Superclass.prototype);</p><p>Subclass.prototype.constructor = Subclass; // do NOT invoke function with ();</p><p>Superclass.call(this, &lt;args&gt;); // optional, but must call to get Superclass’ properties</p><p>example:</p><p>Mammal.prototype = Object.create(Animal.prototype); // inherit Superclass’ methods</p><p>Mammal.prototype.constructor = Mammal; // enables inheritance of Mammal</p><p>Animal.call(this); // inherit Superclass’ properties</p><p>3. For older Javascript (not ideal): Set class’ prototype to a new instance of parent class to connect the subclass’ prototype to the superclass’ __proto__ (aka [[Prototype]]):</p><p>Subclass.prototype = new Superclass();</p><p>Subclass.prototype.constructor = Subclass; // do NOT invoke function with ();</p><p>example: Mammal.prototype = new Animal(); // inherit superclass’ methods+properties</p><p>Mammal.prototype.constructor = Mammal; // this sets constructor = Mammal correctly since “new” sets constructor = Animal;</p><p><strong>constructor usage in ES5:</strong></p><p>If the constructor function explicitly returns a value, then the new instance created is not returned.</p><p>To call the parent’s constructor, use Function’s apply or call with “this” as the context:</p><p>function Mammal (name) { Animal.call(this, name); };</p><p><strong>class &amp; instance properties &amp; methods in ES5:</strong></p><p><strong>1. </strong>Properties AND methods declared within the constructor are INSTANCE members, NOT class/ prototype members!</p><p>2. To create class methods, assign the function to the class’ prototype outside constructor: Animal.prototype.eat = function() { … };</p><p>3. To create class properties, assign the property to the ClassName: Animal.name</p><p>4. Instance properties &amp; methods are created within the constructor:</p><p>this.myName = ‘name’;</p><p>5. To call the superclass method: Superclass.prototype.method.call(this): Animal.prototype.eat.call(this);</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3062caca39b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The 3 faces of an IIFE Module]]></title>
            <link>https://franpham.medium.com/the-3-faces-of-an-iife-module-1fb42ba111d2?source=rss-7dacf21d9917------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fb42ba111d2</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[iife]]></category>
            <category><![CDATA[modules]]></category>
            <dc:creator><![CDATA[Francis Pham]]></dc:creator>
            <pubDate>Thu, 10 Sep 2015 20:56:45 GMT</pubDate>
            <atom:updated>2015-09-10T21:06:48.573Z</atom:updated>
            <content:encoded><![CDATA[<p>There are 3 conventional ways to create an IIFE module. They all return the same value, but syntactically they look different. They all use closures to access private properties of the outer function.</p><p>An IIFE is an Immediately Invoked Function Expression: the outer function is wrapped in parentheses and executed by adding a trailing set of parentheses. When that function executes, it returns an object that has inner functions have can reference private properties via closures.</p><p>Convention #1: declare the functions within the returned object:</p><p>var mod = (function() {</p><p>var privateProp = ‘name’;</p><p>return {</p><p>getName : function() { return privateProp; }</p><p>};</p><p>})();</p><p>2. Convention #2: declare the functions outside the returned object, and use the returned object’s method properties to reference those inner functions:</p><p>var mode = (function() {</p><p>var privateProp = ‘name’;</p><p>function _getName() {</p><p>return privateProp;</p><p>}</p><p>return {</p><p>getName : _getName</p><p>};</p><p>})();</p><p>3. Convention #3: declare the functions outside the returned object, and create an object to assign those inner functions to the obj’s method properties:</p><p>var mod = (function() {</p><p>var privateProp = ‘name’;</p><p>var tempMod = {};</p><p>tempMod.getName = function() {</p><p>return privateProp;</p><p>}</p><p>return tempMod;</p><p>})();</p><p>These 3 ways of creating an IIFE module all create closures that returns an object whose functions can access private properties.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fb42ba111d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>