Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez
Created March 30, 2020 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidPeralvarez/354cad0ee503dae3c7fe020e28728ec2 to your computer and use it in GitHub Desktop.
Save DavidPeralvarez/354cad0ee503dae3c7fe020e28728ec2 to your computer and use it in GitHub Desktop.
JavaScript - this
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Curso de Javascript</title>
</head>
<body>
<script src="scripts.js"></script>
</body>
</html>
var nombreCancion = 'Título de la canción';
var spotify = {
nombreCancion: 'Here comes your man',
artista: 'Pixies',
reproducirCancion: function(){
// console.log( 'Estoy reproduciendo una canción.' );
// console.log( this );
console.log( 'Estoy reproduciendo: ' + this.nombreCancion );
},
anuncioSpotify: function(){
console.log( 'Hola, soy un anuncio.' );
},
premium: {
activado: false,
precio: 7,
mostrarPrecio: function(){
console.log( 'El precio de la suscripción premium es de: ' + this.precio );
}
}
};
// console.log( spotify.nombreCancion );
// console.log( spotify.anuncioSpotify() );
console.log( spotify.reproducirCancion() );
console.log( spotify.premium.mostrarPrecio() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment