I am trying to dynamically call a function inside of an object. Found the apply
function but not fully understanding it. Check out the code below, by triggering Test.checkQueue()
it should in turn call showSomething
"method". Thanks.
var Test = {
, queue : [{action:'showSomething', id:'1234'},{action:'showOther', id:'456'}]
, showSomething: function(what) {
alert(what);
}
, checkQueue : function() {
console.log('checkQueue');
console.log(this.queue);
if (this.queue.length) {
var do = this.queue.shift();
console.log(do);
// action.action(action.id);
do.action.apply(this, do.id || []);
}
}
};