var Class = require('../../utils/Class'); var Button = new Class({ initialize: function Button(pad, index){ this.pad = pad; this.events = pad.manager; this.index = index; this.value = 0; this.threshold = 1; this.pressed = false ; } , update: function (value){ this.value = value; var pad = this.pad; var index = this.index; if (value >= this.threshold) { if (!this.pressed) { this.pressed = true ; this.events.emit('down', pad, this, value); this.pad.emit('down', index, value, this); } } else if (this.pressed) { this.pressed = false ; this.events.emit('up', pad, this, value); this.pad.emit('up', index, value, this); } } , destroy: function (){ this.pad = null ; this.events = null ; } } ); module.exports = Button;