Это видео недоступно.
Сожалеем об этом.

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

Комментарии • 10

  • @muhammadauwal738
    @muhammadauwal738 Год назад +3

    I feel lucky to have found your videos 😁

    • @AskLixi
      @AskLixi  Год назад

      Aww thank Im so happy to help!

  • @mubiruahmed7413
    @mubiruahmed7413 Год назад +2

    👍👍🙏 thx lixi

  • @muhammadauwal738
    @muhammadauwal738 Год назад +3

    Hey how do I add an array as an arguement to a constructor?

    • @AskLixi
      @AskLixi  Год назад +1

      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!

  • @bcastudent-hy5ld
    @bcastudent-hy5ld Год назад +3

    Please use REPLIT 😅😊

    • @AskLixi
      @AskLixi  Год назад

      In fact I am planning to use it, So it will come soon :)

  • @bcastudent-hy5ld
    @bcastudent-hy5ld Год назад +3

    Where are you from 😮