Это видео недоступно.
Сожалеем об этом.
Chapter 16: Javascript Tutorial - What is a Constructor in Javascript?
HTML-код
- Опубликовано: 20 апр 2023
- In this chapter you will learn what is a constructor in javascript and how you can use contructors!
To join my Patreon account visit me:
/ asklixi
Enjoy!
Thank you for Watching!
#asklixi #javascript #javascripttutorial #constructors #construcorsin js
I feel lucky to have found your videos 😁
Aww thank Im so happy to help!
👍👍🙏 thx lixi
Np 😉
Hey how do I add an array as an arguement to a constructor?
This is a great question, to do this I would recommend to simply pass the array as a parameter to the constructor, you can do something like this:
class Person {
constructor(name, age, hobbies) {
this.name = name;
this.age = age;
this.hobbies = hobbies;
}
}
const john = new Person('John', 30, ['reading', 'playing guitar', 'hiking']);
console.log(john);
In this example, the Person constructor takes three parameters: name, age, and hobbies. The hobbies parameter is an array.
Now, When we create a new instance of the Person class (const john = new Person('John', 30, ['reading', 'playing guitar', 'hiking'])), we pass an array as the third argument.
Then Inside the constructor function, we assign the name, age, and hobbies parameters to the corresponding properties of the newly created object (this.name = name;, this.age = age;, and this.hobbies = hobbies;, respectively).
Finally, we log the john object to the console to verify that the array was successfully passed as an argument and assigned to the hobbies property.
I hope this helps!
Please use REPLIT 😅😊
In fact I am planning to use it, So it will come soon :)
Where are you from 😮
Nicaragua :)