+ 2

OOJS question

I am reading Eloquent JS by Marijn Haverbeke and Im confused with the line below. What is the meaning of this? "Sometimes you want to attach some properties directly to your constructor function, rather than to the prototype. Such methods won’t have access to a class instance but can, for example, be used to provide additional ways to create instances."

5th Nov 2018, 12:55 PM
Alquen
Alquen - avatar
1 Odpowiedź
+ 1
Object can be instantiated by attach some properties directly from constructor. E.g. class Temperature { constructor(celsius) { this.celsius = celsius; } const temp = new Temperature(27); // temp instantiated with celsius property equals to 27 Reference: https://eloquentjavascript.net/06_object.html
6th Nov 2018, 11:59 AM
Calviղ
Calviղ - avatar