When I need to pass a function with parameters as a parameter to another function I use a partial function application function, which looks like this:
function wrapFunction(func, params) { // 'params' should be an array
return function() {
return func.apply(this, params);
};
}
This works fine when passing a function like alert(arg), which is not a prototype of any object (as far as I'm convinced). But as soon as I need to pass a prototype function of an object, for example camera.moveTowards(arg1, arg2, ...), argument 'this' in wrapFunction() needs to be replaced by 'camera'. Is there any way to get a reference to a prototype's parent and pass it in place of 'this'?
PS: I don't want to add another argument to wrapFunction, which I would declare every time (like wrapFunction(camera, camera.moveTowards, [arg1, arg2, ...])), because it messes up the readability.