About Object and Extensions [closed]

1

I'm now starting in Javascript I'm learning through websites. I went to an excellent site ( link ) and so far everything was fine. Except that getting to the part of (Objects) the code does not give at all. The point is that the code does not strike me as wrong. I guess I'm not putting the code completely or I'm not saving with the correct extension. I've thought of a lot of things and since I do not say much about inserting code in HTML (which is what I've done), maybe it's to use a program of its own or something. I ask you to help me.

    
asked by anonymous 29.07.2015 / 18:48

1 answer

0

Well, I'll consider that you're running this code below:

var album = new Object();
album.title = "Metallica (Black Album)";
album.released = 1991;
album.showInfo = function() {
  alert("Título do álbum: " + this.title + "Lançado em: " + this.released);
};
album.showInfo();

Run and see in the alert the result.

This is a didactic example, explained step by step by the author. At one point it says:

  

Because the methods are functions, you must add a pair of parentheses - () - when you access them.

Then you call the method (which is a function) of your object:

  

album.showInfo ();

    
29.07.2015 / 19:00