+ 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."
1 Antwort
+ 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