Skip to content

Instantly share code, notes, and snippets.

@nikkaroraa
Last active June 19, 2018 11:51
Show Gist options
  • Save nikkaroraa/16c3c302d384d99078c9cef2f61bfd0b to your computer and use it in GitHub Desktop.
Save nikkaroraa/16c3c302d384d99078c9cef2f61bfd0b to your computer and use it in GitHub Desktop.
Things to clear up before jumping into the world of React

3. How "super" keyword works in JS

The main issue that we will come across in React is the usage of "this" in constructor.

This issue can be summarised as follows:

The JS engine only attaches an object instance to the context variable (this) once you get to the highest prototype in the chain - which is Object

  class Widget extends Resource {
    constructor() {
        console.log(this);   // ReferenceError
        super();
    }
  }
For more info, go here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment