diff --git a/backend/jx_helpers.js b/backend/jx_helpers.js index ab57e3d..28cbd32 100755 --- a/backend/jx_helpers.js +++ b/backend/jx_helpers.js @@ -28,11 +28,14 @@ exports.store = { }; exports.addEvent = function (event, cb) { - if (!events[event]) { - events[event] = []; + if(typeof cb === "function") { + if (!events[event]) { + events[event] = []; + } + events[event].push(cb); + } else { + throw new TypeError("Callback is not a function."); } - - events[event].push(cb); }; exports.emitEvent = function (event, param1, param2, param3) { diff --git a/backend/jxm.js b/backend/jxm.js index 2fb8317..aa70917 100755 --- a/backend/jxm.js +++ b/backend/jxm.js @@ -392,7 +392,11 @@ exports.setEngine = function (app) { * @param listener {function} - Callback function which will be invoked upon emit of the event. */ exports.on = function (event, listener) { - helpers.addEvent(event, listener); + if(typeof listener === "function") { + helpers.addEvent(event, listener); + } else { + throw new TypeError("Listener is not a function."); + } };