I have one module that I'm using for helper methods, in this module I have a method that will set a keyup eventListener on an element that's passed in. I want to call that helper method from a separate module and pass in a callback using the current modules 'this' context.
//helper module constructor---
function ToolsHelper(options) {
"use strict";
this.init(options);
}
//helper module methods---
;(function ($, ba) {
"use strict";
ToolsHelper.prototype = {
constructor: ToolsHelper,
spaceEnterEvent: function (ele, callback) {
var spaceKey = 13,
enterKey = 32;
if (callback === 0) {
callback = null;
}
ele.addEventListener('keyup', function (e) {
e = e || window.event;
var targ = e.target;
if (e.keyCode === spaceKey || e.keyCode === enterKey) {
e.preventDefault();
targ.click();
if (callback !== null) {
callback();
}
}
});
return true;
}
}
$(document).on("baCoreReady", function () {
ba.ToolsHelper = new ToolsHelper();
});
})(jQuery, ba);
I'm attempting to call this helper from another module [moduleB] using:
ba.ToolsHelper.spaceEnterEvent(trigger, self.updateTabIndexes);
//'self' is set to 'this' in moduleB
Once self.updateTabIndexes() is fired from within moduleB im getting 'cannot read property "settings" of undefined' error - 'settings' is an object defined from within moduleB