Can I call a function inside a Require.js module with the function name in a string ?
define(['jquery', function( $ ) {
var init = function() {
var elems = {};
for( var x=0; x<$('.js-elem').length; x++ ) {
elems[x] = {
dom: {
el: $('.js-elem').eq(x)
},
get animation() {
return this.dom.el.data('animation');
}
}
setEvents( elems[x] );
}
};
var setEvents = function( elem ) {
elem.dom.el.on('click', function( e ) {
console.log( elem.animation ); // = String "anim1"
this[ elem.animation ]( elem ) // = window.anim1 (Out of require.js module scope)
});
};
var anim1 = function( elem ) {
//...
};
return {
init: init
};
});