Published
Edited
Nov 20, 2019
1 fork
Insert cell
md`# Classes, Instances, Inheritance`
Insert cell
md`## REPASITO REDUCE`
Insert cell
[1,2,3,4].reduce(function(acc,e){
console.log("Acc:",acc,"element:",e);
return e+acc;
})
Insert cell
{
function suma(a,b){
return a+b
}

let x = [suma,suma,suma,suma].reduce(function(acc,e){
return function(){
return e(1,acc(1))
}
},function(x){
return x;
})()
return x;
}

Insert cell
md`## Classes`
Insert cell
contador = {

return {
vueltas: 0,
dateUnaVuelta: function(){
this.vueltas++;
}
}

}
Insert cell
indurain = {
return {
vueltas: 0,
dateUnaVuelta: function(){
this.vueltas++;
}
}
}
Insert cell
contador
Insert cell
{
contador.dateUnaVuelta()
contador.dateUnaVuelta()
contador.dateUnaVuelta()
contador.dateUnaVuelta()
}
Insert cell
indurain.dateUnaVuelta()
Insert cell
console.log(contador, indurain)
Insert cell
class Ciclista {
constructor(nombre, saludo){
this.nombre = nombre + " el puto crack";
this.vueltas = 0;
if(saludo){
this.hola = saludo;
}
}
dateUnaVuelta(){
this.vueltas +=1;
}
}
Insert cell
c1 = new Ciclista("Indurain")
Insert cell
c2 = new Ciclista("Alberto")
Insert cell
c2.__proto__.hola = "pepe"
Insert cell
c1.dateUnaVuelta()
Insert cell
c3 = new Ciclista("juan","que tal")
Insert cell
c2.hola
Insert cell
x = c2
Insert cell
x.dateUnaVuelta()
Insert cell
c2.hola
Insert cell
c3.__proto__.hola
Insert cell
m = function(){
return 3;
}
Insert cell
m instanceof Object
Insert cell
md`# Inheritance`
Insert cell
class Animal {
constructor(name,sound){
this.name = name;
this.sound = sound || "no-sound"
}
makeSound(){
let sound = this.sound.repeat(2);
console.log(sound)
return sound;
}
}
Insert cell
a = new Animal("Serpiente")
Insert cell
a.makeSound()
Insert cell
class Gato extends Animal{
constructor(name){
super(name, "pepe")
console.log(this)
this.sound = "Miau"
console.log(this)
this.wiskas = true
}
maulla(){
return "uyuyuyuy -> https://www.youtube.com/watch?v=2F3GlAiboVs"
}
}
Insert cell
g = new Gato("Garfield")
Insert cell
g.makeSound()
Insert cell
a instanceof Animal
Insert cell
a instanceof Gato
Insert cell
g instanceof Gato
Insert cell
g instanceof Animal
Insert cell
g.maulla()
Insert cell
a.maulla()
Insert cell
a.makeSound()
Insert cell
g.makeSound()
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more