-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (29 loc) · 898 Bytes
/
index.js
File metadata and controls
42 lines (29 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Toggable{
constructor(el){
// incializar el estado interno
this.el = el
this.el.innerHTML = 'Off'
this.activated = false
this.el.addEventListener('click', this.onClick.bind(this)) // quien va ser el this?
}
onClick(ev){
// cambiar el estado interno de on a off o de off a on
this.activated = !this.activated
this.toggleText()
}
toggleText(){
// cambiar el texto
this.el.innerHTML = this.activated ? 'On' : 'Off'
}
}
const button = document.getelementById('buton')
const miBoton = new Toggable(buton)
// Otra forma de manejar el bind
function saludar(nombre, apellido){
console.log(`Hola ${nombre} ${apellido}!`)
}
//saludar("Sacha", "Lifszyc")
const saludarSachas = saludar.bind(null, "Sacha")
saludarSachas("Martinez")
// Función bind: documentación:
// https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Function/bind