So I've been trying to get this callback working inside of an object and I was just wondering if:
1) it's possible, 2) special syntax is required.
So instead of just having a regularly declared function:
function callback() {}
And passing that to another function by reference:
doSomething(callback)
Im trying to pass an object property that contains a function:
{
prop: function() {}
}
and send that as a call back.
The problem is, passing the reference of prop throws an error:
doSomething(prop):
throws: Uncaught SyntaxError: Unexpected token :
If a complete example is needed, let me know.
Thanks, Ken
** Edit **
Okay so after some confusion I'm typing a fairly complete example.
var obj = {
init: function() {
this.some_function(this.callback_function)
},
some_function: function(callback) {
callback();
},
callback_function: function() {
// Callback!
}
}
This is throwing the unexpected token error unless I put the () when I pass this.callback_function as an argument to some_function().
Thanks and sorry for not posting a fuller-example earlier.
Ken
thiskeyword does not refer toobjwhenobj.callback_functionis called.