Specifically, I'm interested in how to get the code below to work, logging as per the comments.
function someWeirdness(func) {
var funcThis = undefined; // Instead of undefined, access to what,
// if anything, func is bound to
// (func.this doesn't work, but that would be
// it if it did).
console.log(funcThis);
}
function greet(greeting) {
console.log([greeting || "Hello", this.name].join(" "));
}
var obj = {
name: "object"
};
greetObj = greet.bind(obj);
someWeirdness(greetObj); // logs obj
The application would be something more along the lines of:
function compositionalMagic(func, params) {
params = Array.isArray(params) ?
params : Array.prototype.slice.call(arguments, 1);
// Additional processing and hooplah
func.apply(func.this, params);
}