diff --git a/js/karel.js b/js/karel.js index a3af799..8c8473d 100644 --- a/js/karel.js +++ b/js/karel.js @@ -85,10 +85,9 @@ var Runtime = function (world) { self.disableStackEvents = false; self.load([['HALT']]); + self.events = new EventTarget(); }; -Runtime.prototype = new EventTarget(); - Runtime.HALT = 0; Runtime.LINE = 1; Runtime.LEFT = 2; @@ -118,6 +117,22 @@ Runtime.CALL = 25; Runtime.RET = 26; Runtime.PARAM = 27; +Runtime.prototype.addEventListener = function (type, listener) { + this.events.addEventListener(type, listener); +}; + +Runtime.prototype.removeEventListener = function (type, listener) { + this.events.removeEventListener(type, listener); +}; + +Runtime.prototype.dispatchEvent = function (evt) { + this.events.dispatchEvent(evt); +}; + +Runtime.prototype.fireEvent = function (type, properties) { + this.events.fireEvent(type, properties); +}; + Runtime.prototype.load = function (opcodes) { var self = this; var opcode_mapping = [