I wrote some code like this
function Flasher() {
this.cards = []
this.map = {
14: this.flip
}
}
Flasher.prototype.flip = function() {
alert(this.cards.length)
}
flasher = new Flasher()
flasher.map[14]()
Unfortunatley, the this
object becomes the map object within the flip
method and an error occurs (because cards
is undefined).
How can I get this to function as intended? Calling flip
indirectly via map
is necessary, but I would like access to the original object within flip
.