<?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: Adewumi Emmanuel Femi</title>
    <description>The latest articles on DEV Community by Adewumi Emmanuel Femi (@pitypec).</description>
    <link>https://dev.to/pitypec</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%2F780772%2F4c6ee36c-9043-40bf-a33f-38688a040ffd.jpeg</url>
      <title>DEV Community: Adewumi Emmanuel Femi</title>
      <link>https://dev.to/pitypec</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pitypec"/>
    <language>en</language>
    <item>
      <title>Demystifying 'This' in Javascript</title>
      <dc:creator>Adewumi Emmanuel Femi</dc:creator>
      <pubDate>Tue, 01 Feb 2022 16:53:36 +0000</pubDate>
      <link>https://dev.to/pitypec/demystifying-this-in-javascript-4oph</link>
      <guid>https://dev.to/pitypec/demystifying-this-in-javascript-4oph</guid>
      <description>&lt;p&gt;The first question a beginner in programming would ask is, "what is 'this'? Well, I don't mean the kind you have in mind. In this context I'm talking about the 'this' that accompanies every block of code or function. So where does 'this' come from?&lt;/p&gt;

&lt;p&gt;Every code block always has a context called 'this'. Most beginners always wondered where the this comes from (I was most beginners, most beginners was me). &lt;/p&gt;

&lt;p&gt;When a code block is created, in this example, we will be using a function. All functions are prototype of the Object class, i.e. they inherit from the Object class. First we have to look at function from the angle of being an object. Let's take a look at what happens when you create a function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getAllUser(){
   let this = {} //(1)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a function is declared we have an Object initialized or created called 'this' as seen in (1) above. All methods and variables are created inside the 'this' object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function createUser(firstName, lastName){
    let firstName = firstName;
    let lastName = lastName;
}
createUser.prototype = {
      fullName: function(){
          Alert(`Full name is ${this.firstName} ${this.lastName})
      }
}
function createUser(firstName, lastName){
    let this = {
      firstName: firstName,
      lastName : lastName
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The object class is parent to many other classes and it forms the basis of many classes we use often. The concept of 'this' is understandable because function itself is a prototype of Object class. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Classes Under the Hood</title>
      <dc:creator>Adewumi Emmanuel Femi</dc:creator>
      <pubDate>Fri, 31 Dec 2021 23:00:32 +0000</pubDate>
      <link>https://dev.to/pitypec/classes-under-the-hood-5go7</link>
      <guid>https://dev.to/pitypec/classes-under-the-hood-5go7</guid>
      <description>&lt;p&gt;Ever heard the phrase, "in software engineering, everything is an object"? Well, we are going to delve into three major things: How classes in javascript work under the hood, what classes are built on and also the fact that a class is a function basically. &lt;/p&gt;

&lt;p&gt;In order to understand how classes work under the hood, we need to touch on two concept in javascript: prototypal inheritance and constructor function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Constructor Function
&lt;/h2&gt;

&lt;p&gt;When you create a class, you are basically creating a function. This type of function is called a constructor function and it is always initialized with the keyword 'new.' It is a convention in Javascript to start a constructor function with a capital letter. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd69stj9jgw7s0gaxxsak.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd69stj9jgw7s0gaxxsak.png" alt="How to create a constructor function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The (*) represents the creation of the constructor function, (**) represents how to create an object from the constructor function. The line (***) creates an object from the construction function using an inbuilt property 'constructor' (I don't think Ostriches are blue thou). Whenever you create a class you are creating a constructor function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prototypal Inheritance
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let Animal = { 
  breath: true,
  walk() {
    Alert("All Animal's walk");
  },
};

let Bird = {
  __proto__: Animal, (*) // Bird becomes a prototype of Animal
  fly: true,
};

alert(Bird.walk()) (**) // All Animal's walk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All objects have a property called [[prototype]] this is referenced or called when __proto__ is set on the Bird object to Animal. The line (*) signifies I am inheriting or I am a prototype of Animal; therefore I have access to everything inside the Animal object. The __proto__ can go as deep as possible but an object may not inherit from two at a time i.e you can only inherit from one other object.&lt;/p&gt;

&lt;p&gt;How does the above tie into classes and how classes work? Well, when you create a class you create a constructor function and when your class has a constructor you are using the constructor property under the hood.&lt;/p&gt;

&lt;h2&gt;
  
  
  To sum it all up
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Class User{
   constructor(name, age){
      this.name = name;
      this.age = age;
   }
}
const user = new User("David" "2")

function User(name, age){ // This is equivalent to creating a class User
   this.name = name;
   this.age = age;
}
const user = new User()
const user1 = new user.constructor("David" "2") // This is what the User class constructor above calls under the hood
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Animal{
  walk(){
    Alert("All Animal's walk")
  }
}
class Bird extends Animal{ // When you extend animal or you inherit from the Animal class, a __proto__ object property in Bird is created and it refrences Animal
  __proto__: Animal
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
