I wish to implement this lib:
var timer = new Tock({
this.callback: callbackFunction,
this.interval: 10,
this.complete: completeFunction,
});
However, I wish to be able to make dynamic calls:
var milkshake = my_milkshakes[next];
var timer = new Tock({
this.callback: makeMoreMilkshakes(), // (Call version 2)
this.interval: shakeTime,
this.complete: bringThemToTheYard
});
function bringThemToTheYard(){
return setNextCallbackFunction();
}
The problem here seems to be that I cannot reach outside the scope of the initialization. In Java, I can easily pass arguments to the constructor, except in the case when a function handle is expected.
By abstract I mean that the code is not reusable through reference, but this is admittedly loose terminology.
My goal is to initialize a single new timer call to create new timers. I need 5 different timers. Ideally, a single timer would be enough because the timers are started and stopped in linear time.
My main problem is that I cannot set (for example) this.interval to a dynamic variable x, because I do not know how to pass a value into the constructor.
My implementation was based on the "code" from the documentation below:
var timer = new Tock({
countdown: true,
interval: 10,
callback: someCallbackFunction,
complete: someCompleteFunction
});
this.callbackas a key of an object doesn't make a whole lot of sense, what's that supposed to be? 3) It's unclear what you're trying to achieve.{ this.callback: .. }is still a syntax error.new Tock({...}), you are passing a value to the constructor, namely an object literal containing various properties. But your object literal is malformed, because the keys can only be string literals, notthis.something.