Skip to content

Instantly share code, notes, and snippets.

@r3dm1ke
Created February 6, 2020 18:39
Show Gist options
  • Select an option

  • Save r3dm1ke/13c0feaae7a93b50bca994854cc6b0d3 to your computer and use it in GitHub Desktop.

Select an option

Save r3dm1ke/13c0feaae7a93b50bca994854cc6b0d3 to your computer and use it in GitHub Desktop.
Explaining JS constructor functions
function Car(name, make) {
// Here, this is not a reference to outer object
// But a placeheloder object you can use to construct the
// desired value
this.name = name;
this.make = make;
// you do not have to return anything, as this is automatically returned
}
const myCar = new Car('Outback', 'Subaru');
console.log(myCar.name); // Outback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment