Created
February 6, 2020 18:39
-
-
Save r3dm1ke/13c0feaae7a93b50bca994854cc6b0d3 to your computer and use it in GitHub Desktop.
Explaining JS constructor functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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