Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Instantiate an object that stores a reference of another object (inaccessible)

I’m a C# developer and my girlfriend started studying JS.
Although I don’t like this language, I try to help him with the objects.

I want to access my ‘Season’ object from the ‘Serie’ object which stores a reference to it, but impossible and I don’t understand.

I’m not used to being assisted in a programming language, so much by dynamic typing (although C# can do it)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class Serie
 {
   constructor(title, season, year)
   {
     this.title = title;
     this.season = season;
     this.year = year;
   }
 }

class Season
{
  contructor(number, episode)
  {
    this.number = number;
    this.episode = episode;
  }
}

class Episode
{
  constructor(title, duration, hasBeenWatched)
  {
    this.title = title;
    this.duration = duration;
    this.hasBeenWatched = hasBeenWatched;
  }
}

let episode1 = new Episode("I'am s**", 45, false);
let saison1 = new Season(1, episode1);
let serie1 = new Serie("The Story of Tau", saison1, 1999);

document.querySelector('#first-episode-info').innerText = `Série: ${serie1.title}
Saison: ${serie1.season.number} 
  1 ${serie1.season.episode.title}
          ${serie1.season.episode.duration} min
          ${serie1.season.episode.hasBeenWatched ? 'Already watched' : 'Not yet watched'}
${serie1.year}`;

thank you

I want to access the properties of my ‘Season’ object from another object

I did a lot of research on the internet but I can’t find the solution (the evolution of the language changes the syntax)

Please understand that I have no experience in this language.

>Solution :

You made a typo.

class Season
{
  // contructor -> con(s)tructor
  constructor(number, episode)
  {
    this.number = number;
    this.episode = episode;
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading