Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez
Created April 1, 2020 16:03
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/64e97ac6d9d4dce446400e7ffa615a68 to your computer and use it in GitHub Desktop.
Save DavidPeralvarez/64e97ac6d9d4dce446400e7ffa615a68 to your computer and use it in GitHub Desktop.
JavaScript - Los prototipos
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Curso de Javascript</title>
</head>
<body>
<script src="scripts.js"></script>
</body>
</html>
function Serie( titulo, puntuacion, plataforma ){
// Constructor
this.titulo = titulo;
this.puntuacion = puntuacion;
this.plataforma = plataforma;
}
// Prototipo
Serie.prototype.detallesSerie = function(){
return 'Título: ' + this.titulo + ' | Puntuación: ' + this.puntuacion + ' | Ya disponible en: ' + this.plataforma;
};
Serie.prototype.constante = 'No cambia nunca';
// Instancia
var serie1 = new Serie( 'La casa de papel', 8.5, 'Netflix' );
var serie2 = new Serie( 'Silicon Valley', 7, 'HBO' );
console.log( serie1.constante );
console.log( serie1.detallesSerie() );
console.log( serie2 );
console.log( serie2.detallesSerie() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment