<?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: Nicole Schmidlin</title>
    <description>The latest articles on DEV Community by Nicole Schmidlin (@schmidlinicole).</description>
    <link>https://dev.to/schmidlinicole</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%2F763159%2Ffa37f877-c3c2-4e6d-b4b5-8759f4fc9d50.png</url>
      <title>DEV Community: Nicole Schmidlin</title>
      <link>https://dev.to/schmidlinicole</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/schmidlinicole"/>
    <language>en</language>
    <item>
      <title>How to turn your Ruby on Rails project into a Shopify app</title>
      <dc:creator>Nicole Schmidlin</dc:creator>
      <pubDate>Fri, 18 Feb 2022 13:00:26 +0000</pubDate>
      <link>https://dev.to/schmidlinicole/how-to-turn-your-ruby-on-rails-project-into-a-shopify-app-1ihh</link>
      <guid>https://dev.to/schmidlinicole/how-to-turn-your-ruby-on-rails-project-into-a-shopify-app-1ihh</guid>
      <description>&lt;p&gt;For the past few weeks, I spend my time turning a Rails project into a Shopify app and… it can be a pain. So I documented what worked and what didn’t and I hope this guide will make your introduction to Shopify app development at least a little bit easier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preparations
&lt;/h2&gt;

&lt;p&gt;Of course, you can’t start coding right away, but luckily it’s only three things that need to be done:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Shopify Partner account&lt;/li&gt;
&lt;li&gt;Development Store&lt;/li&gt;
&lt;li&gt;ngrok account&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Shopify Partner account
&lt;/h3&gt;

&lt;p&gt;If you want to develop an app for Shopify, you need to create a &lt;a href="https://www.shopify.com/partners" rel="noopener noreferrer"&gt;Shopify Partners&lt;/a&gt; account. It’s really easy, you just need to sign up for it, and then you’re done. Plus, it’s free!&lt;/p&gt;

&lt;h3&gt;
  
  
  Development store
&lt;/h3&gt;

&lt;p&gt;After creating a Partner account, you need to create a store. Otherwise, you wouldn’t be able to test your app inside a store.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to your Shopify Partners account and click on &lt;em&gt;Stores&lt;/em&gt; on the menu on the left side.&lt;/li&gt;
&lt;li&gt;Click &lt;em&gt;Add Store&lt;/em&gt; and choose the option &lt;em&gt;Development Store&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Fill out all the necessary information and done!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It should redirect you to the store’s dashboard.&lt;/p&gt;

&lt;h3&gt;
  
  
  ngrok account
&lt;/h3&gt;

&lt;p&gt;You will also need a &lt;a href="https://ngrok.com/" rel="noopener noreferrer"&gt;ngrok&lt;/a&gt; account. Simply sign up and download the correct version for your laptop and follow the instructions on the website. If the command on &lt;em&gt;Setup &amp;amp; Installation&lt;/em&gt; doesn’t work for you, you can also do it manually as described in the &lt;em&gt;Your Authtoken&lt;/em&gt; section.&lt;/p&gt;

&lt;p&gt;Open a terminal and start the server with &lt;code&gt;ngrok http 3000&lt;/code&gt;. Your terminal should look something like this:&lt;br&gt;
&lt;a href="https://media2.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%2F1u4ef14bg9aocjixncqf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F1u4ef14bg9aocjixncqf.png" alt="ngrok running in the terminal" width="800" height="292"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If it didn’t work and you got ERR_NGROK_108, you might need to kill the current ngrok session and then restart it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# kill and restart
$ kill `pgrep ngrok`
$ ngrok http 3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating an app
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create an app in the Partner’s dashboard
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Like for the development store, click on Apps on the menu on the left side and then on Create app.&lt;/li&gt;
&lt;li&gt;Choose whether you want to create a custom or public app, I will choose a public app.&lt;/li&gt;
&lt;li&gt;After that, input all the necessary information.
For &lt;em&gt;App URL&lt;/em&gt; use the URL provided by ngrok. In my case with the example from above it would be &lt;a href="https://cbd2-somemorestuff.ngrok.io" rel="noopener noreferrer"&gt;https://cbd2-somemorestuff.ngrok.io&lt;/a&gt; . For &lt;em&gt;Allowed redirection URL(s)&lt;/em&gt;, put in the same ngrok URL, but with &lt;em&gt;/auth/shopify/callback&lt;/em&gt; at the end. This way, Shopify will be able to authenticate your app when you install it to your store.
&lt;img src="https://media2.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%2Fiwppl3b6m5vd20x5k7gq.png" alt="URLs section when creating an App" width="800" height="467"&gt;
&lt;/li&gt;
&lt;li&gt;Lastly, click on Create app.
Done! Now you should see your app API key and secret key.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By default, &lt;em&gt;embedded app&lt;/em&gt; should be enabled, but still, check if it is to be sure. To do so, click on App setup. Scroll down until you reach the Embedded app section and click on the Manage button. Enable &lt;em&gt;&lt;strong&gt;Embed your app in Shopify admin&lt;/strong&gt;&lt;/em&gt; if it’s currently disabled.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add shopify_app gem
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Take an existing project or create a new one and cd into its directory:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rails new shopify_rails_app_name
$ cd shopify_rails_app_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2 Add the gem manually or run the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ bundle add shopify_app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3 Install the generator with your own api key, secret and ngrok redirect URL (the one with /auth/shopify/callback at the end).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rails generate shopify_app:install -api_key=your_api_key 
-secret=your_app_secret -redirect_uri=your_redirect_uri
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might get the same long error message as me that starts like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;in `method_missing': undefined method `assets' for #&amp;lt;Rails::Application::Configuration:0x000000010c7d75a0...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you do, then you need to add &lt;code&gt;require “sprockets/railtie”&lt;/code&gt; at the top of your &lt;code&gt;application.rb&lt;/code&gt; in the config folder and create a &lt;code&gt;manifest.js&lt;/code&gt; file in &lt;code&gt;app &amp;gt; assets &amp;gt; config&lt;/code&gt;. Run the command once more.&lt;br&gt;
4 Generate the home controller and shop model&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rails generate shopify_app:home_controller
$ rails generate shopify_app:shop_model
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5 Run the pending migrations&lt;br&gt;
Before you execute the command, go to your &lt;code&gt;routes.rb&lt;/code&gt; file and check if you have one or two &lt;code&gt;root&lt;/code&gt; defined. By running the home controller command from step 4, Shopify will add &lt;code&gt;root :to =&amp;gt; ‘home#index’&lt;/code&gt;. Leave it and comment out your other root declaration. Otherwise, the installation won’t work (you can change it back later).&lt;br&gt;
When you only have one &lt;code&gt;root&lt;/code&gt; defined, run the migration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rails db:migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6 Add API key and secret to .env&lt;br&gt;
Open the .env file or create one in the root of your project and define your API key and secret like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SHOPIFY_API_KEY=Your Shopify API key
SHOPIFY_API_SECRET=Your Shopify API secret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And lastly, not necessary, but I still think you should do it: Check out all the changes the gem made (HomeController, ProductsController, migration, etc.).&lt;/p&gt;

&lt;h3&gt;
  
  
  Connect App to Store
&lt;/h3&gt;

&lt;p&gt;Start the rails server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rails s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Visit the ngrok URL you defined as the App’s URL.&lt;/li&gt;
&lt;li&gt;You should now see an input field asking you to enter your shop domain. Enter it and click Install app.
&lt;img src="https://media2.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%2F7x1uu7do5rztqbfq0uui.png" alt="shopify app pop up asking to enter the shop domain" width="800" height="319"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you forgot your shop domain, simply click on your store in your partner dashboard and it should be displayed on the right side.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It should connect to your store and you should see this “You are about to install [your app name]” message. Click on the “Install unlisted app” button.
&lt;img src="https://media2.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%2Fohxtp457ym69sz3cona6.png" alt="View asking you to install unlisted app" width="760" height="590"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Your app is now installed!&lt;br&gt;
Click on &lt;em&gt;Apps&lt;/em&gt; on your &lt;em&gt;store&lt;/em&gt; dashboard (not your partner dashboard) and you will see your app listed under &lt;em&gt;Installed apps&lt;/em&gt;.&lt;br&gt;
&lt;a href="https://media2.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%2Fyenmppq1g5sy635k9ipj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fyenmppq1g5sy635k9ipj.png" alt="Installed apps" width="800" height="294"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on your app to see it running!&lt;br&gt;
If it’s not running, make sure your ngrok tunnel and rails server are both running. Also, if you cancel the ngrok tunnel and restart it, you will get a different URL and thus you will need to change your app’s URL and redirect URL in the partner’s dashboard.&lt;/p&gt;
&lt;h3&gt;
  
  
  Make it work
&lt;/h3&gt;

&lt;p&gt;When you click on your app, you will see the default page of a Shopify App. It will display something along the lines of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Products
Loading...
There are currently no webhooks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find it in &lt;code&gt;app/views/home/index.html.erb&lt;/code&gt; in case you want to use it as your starting page or edit it or just play around.&lt;/p&gt;

&lt;p&gt;If you wanted to change your &lt;code&gt;root&lt;/code&gt; and you were to simply change it in the &lt;code&gt;routes.rb&lt;/code&gt; file, you would see that it still loads, but it doesn’t work. If you click on a navigation item (to get to the &lt;em&gt;About&lt;/em&gt; page for example), nothing happens. That is because for every controller we access in our Shopify App, we need to include the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;include ShopifyApp::EmbeddedApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you hover over the About item in your navigation, you will see that it would redirect you to localhost:3000/about which Shopify cannot access. By including the code above, it changes it to your ngrok URL (&lt;a href="https://cbd2-somemorestuff.ngrok.io/about" rel="noopener noreferrer"&gt;https://cbd2-somemorestuff.ngrok.io/about&lt;/a&gt;), making it possible for Shopify to access.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank you
&lt;/h2&gt;

&lt;p&gt;Thank you for reading all that and I hope I was able to give you an easier start to creating a Shopify App than the one I had.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>shopify</category>
    </item>
    <item>
      <title>What is a prototype in JavaScript?</title>
      <dc:creator>Nicole Schmidlin</dc:creator>
      <pubDate>Mon, 29 Nov 2021 07:11:46 +0000</pubDate>
      <link>https://dev.to/schmidlinicole/what-is-a-prototype-in-javascript-33o9</link>
      <guid>https://dev.to/schmidlinicole/what-is-a-prototype-in-javascript-33o9</guid>
      <description>&lt;p&gt;When I started working on a project with Vue.js, I came to the realization that I do not know much about JavaScript. Since then I’ve been looking into JS which then lead me to Object Oriented Programming in JavaScript. I learned about many things, but the concept I struggled the most with was probably prototypes.&lt;/p&gt;

&lt;p&gt;With this blog post I hope I can explain it in an understandable way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Small introduction
&lt;/h2&gt;

&lt;p&gt;A constructor is a function that creates new objects. In JavaScript it looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Person(name, age) {
   this.name = name;
   this.age = age;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The syntax to create a new object with a constructor looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const me = new Person("Nicole", 19);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;me&lt;/code&gt; now has the &lt;code&gt;name&lt;/code&gt; “Nicole”, and &lt;code&gt;age&lt;/code&gt; 19. Easy and simple as you would expect.&lt;/p&gt;

&lt;p&gt;Now imagine we wanted to create an object &lt;code&gt;Person&lt;/code&gt; with the properties arms, hands, fingers, and name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Person(arms, hands, fingers, name) {
   this.arms = arms;
   this.hands = hands;
   this.fingers = fingers;
   this.name = name;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you create four instances of &lt;code&gt;Person&lt;/code&gt;, it will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const person1 = new Person(2, 2, 10, "Alice");
const person2 = new Person(2, 2, 10, "Bob");
const person3 = new Person(2, 2, 10, "Ursula");
const person4 = new Person(2, 2, 10, "Hanspeter");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty annoying and very repetitive… That’s when prototypes become useful.&lt;/p&gt;

&lt;h1&gt;
  
  
  Prototypes
&lt;/h1&gt;

&lt;p&gt;Prototypes are used to share properties among all instances of an object. Take the example from above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Person.prototype = {
   constructor: Person,
   arms: 2,
   hands: 2,
   fingers: 10
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this prototype object, creating four instances of &lt;code&gt;Person&lt;/code&gt; with the constructor looks much cleaner and is also less work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Person(name) {
   this.name = name;
}
const person1 = new Person("Alice");
const person2 = new Person("Bob");
const person3 = new Person("Ursula");
const person4 = new Person("Hanspeter");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I said, much smaller and less repetitive work, but they all have the same properties as the ones created above without a prototype.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F6x708u88xq5me7up53uu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F6x708u88xq5me7up53uu.png" alt="with vs without prototype" width="800" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Not only does it look cleaner, but it is easier to change the values.&lt;/p&gt;

&lt;p&gt;Let’s say you — for some really stupid reason — typed in 2 hands for each person, but the program actually only creates people with one hand (why we would need the properties arms and fingers is beside the point now). You would have to go through &lt;em&gt;every. single&lt;/em&gt;. instance of the object and change not only the value 2 hands, but also 10 fingers. With only four instances, you would need to make eight changes. With the prototype, you will only ever need to make two changes.&lt;/p&gt;

&lt;p&gt;It’s not the best example, but I think it gets the point across.&lt;/p&gt;

&lt;h2&gt;
  
  
  Single prototype property vs prototype object
&lt;/h2&gt;

&lt;p&gt;Above I used a prototype &lt;em&gt;object&lt;/em&gt; which is good when many properties should be shared. However, if there is only one shared property, you can write it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Person.prototype.age = 30;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No need to make it bigger than it has to be.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prototype functions
&lt;/h2&gt;

&lt;p&gt;It is also possible to store functions as properties with a prototype.&lt;br&gt;
Prototype object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Person.prototype = {
   introduce: function() {
      console.log(`Hello, my name is ${this.name}`);
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Single prototype property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Person.prototype.introduce = function(){
   console.log(`Hello, my name is ${this.name}`);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  constructor: person
&lt;/h2&gt;

&lt;p&gt;You might have noticed that I defined the constructor in the prototype object. This is important to do, because if we do not define the constructor, the objects will have &lt;code&gt;Object&lt;/code&gt; as its constructor and not &lt;code&gt;Person&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Alright, now let’s take this sentence apart to make it clearer.&lt;/p&gt;

&lt;p&gt;You have a constructor for an 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 Person(name, age){
   this.name = name;
   this.age = age;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you create an object with this constructor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const me = new Person("Nicole", 19);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The constructor of &lt;code&gt;me&lt;/code&gt; is &lt;code&gt;Person&lt;/code&gt;. I think that much is clear.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;me.constructor === Person
→ true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, when you create a prototype object for &lt;code&gt;Person&lt;/code&gt; and do not define the constructor, &lt;code&gt;me&lt;/code&gt; will have the constructor &lt;code&gt;Object&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Person.prototype = {
   introduce: function() {
      console.log(`Hello, my name is ${this.name}`);
   }
}
const me = new Person("Nicole", 19);
console.log(me.constructor === Person);
console.log(me.constructor === Object);
→ false
  true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h2&gt;
  
  
  The Prototype chain
&lt;/h2&gt;

&lt;p&gt;To explain the prototype chain, let’s focus only on objects first. When you create an object, you can check its properties with &lt;code&gt;hasOwnProperty&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But where does this come from? We never defined it anywhere, yet we can use it. The answer is that all objects &lt;em&gt;inherit&lt;/em&gt; from &lt;code&gt;Object&lt;/code&gt; which has its own prototype properties. You can check it by creating a simple object and check its constructor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let exampleObject = {
   something: "hi"
}
console.log(exampleObject.constructor === Object);
→ true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So all objects stem from &lt;code&gt;Object&lt;/code&gt;, can use its prototype properties and have &lt;code&gt;Object&lt;/code&gt; as a constructor. This makes sense.&lt;/p&gt;

&lt;p&gt;Now, when you create a prototype &lt;strong&gt;object&lt;/strong&gt;, it is an object and thus inherits from &lt;code&gt;Object&lt;/code&gt;. That is why you have to define the constructor or otherwise your instances of &lt;code&gt;Person&lt;/code&gt; will have the constructor &lt;code&gt;Object&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Object.prototype&lt;/code&gt; -inherited by-&amp;gt; &lt;code&gt;Person.prototype ={}&lt;/code&gt; -inherited by-&amp;gt; &lt;code&gt;me&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Thank you
&lt;/h1&gt;

&lt;p&gt;To be honest, I did not expect this article to get that long (I don’t know what happened), so if you made it till here, seriously, thank you for reading.&lt;/p&gt;

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