I can call a function directly (I'll use alert
as an example) like so
alert("Hello World!"); // pops up an alert window
However, when I put a function in an object, calling it no longer works:
d = {func: alert};
d.func("Hello World!"); // doesn't do anything
d["func"]("Hello World!"); // also doesn't do anything
I figured maybe I needed to explicitly pass in a blank this
argument, so I tried
d.func(null, "Hello World!") // still nothing
but to no avail. Interestingly, this does work
d.func.apply(null, ["Hello World!"]); // success!
but that's so gratuitously verbose it makes my teeth hurt (to quote JWZ). Is there a more concise, less ugly way?