Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez
Created March 31, 2020 09:37
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/1f19c0bab122851bc69347c338807a1b to your computer and use it in GitHub Desktop.
Save DavidPeralvarez/1f19c0bab122851bc69347c338807a1b to your computer and use it in GitHub Desktop.
JavaScript - Las clases antes de las clases
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Curso de Javascript</title>
</head>
<body>
<script src="scripts.js"></script>
</body>
</html>
var serie = {};
console.log( serie );
// Función = Clase = Objeto
function Serie( titulo, puntuacion, plataforma ){
// Propiedades
// this.titulo = 'La casa de papel';
// this.puntuacion = 8.5;
// this.plataforma = 'Netflix';
// Constructor
this.titulo = titulo;
this.puntuacion = puntuacion;
this.plataforma = plataforma;
// Métodos
this.detallesSerie = function(){
return 'Título: ' + this.titulo + ' | Puntuación: ' + this.puntuacion + ' | Ya disponible en: ' + this.plataforma;
}
}
// Instancia
var serie1 = new Serie( 'La casa de papel', 8.5, 'Netflix' );
var serie2 = new Serie( 'Silicon Valley', 7, 'HBO' );
console.log( serie1 );
console.log( serie1.detallesSerie() );
console.log( serie2 );
console.log( serie2.detallesSerie() );
console.log( serie1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment