T
Thomas 'PointedEars' Lahn
nick said:What about arguments.callee? That's good enough for returning a
reference to the same function.
But a function is not necessarily a method of the same object. You need to
keep a reference to the object that has the function as a method, or you
will end up having `this' refer to the global object on subsequent calls.
(Unless, of course, all your methods are global, but then you have another
problem to solve first.)
Granted, but how much more expensive,
Much.
and what's the tradeoff?
Pardon?
If average joe web designer screws up the first example 25% less than the
second, it might be worth those few extra milliseconds per page load.
I do not write for "joe web designer". I write for people who can make
proper use of their brain.
What?
(Polite people ask for clarification differently. See also my [not so
random] sig ;-))
An extra comma in the right place should remove the ambiguity:
BTW, few would consider spoiling the current execution context's
namespace declaring functions when using Array initializers,
as anonymous function expressions would be readily available then.
This means the register function must be more complex, unless you want
to register a single key handler like this: register([[key,func]])
With the self-calling approach the register() method must be more
complex instead; it must use a closure to work on the initial calling
object when self-called.
this.register = function (key, onPress, onRelease) {
if (!initted) init();
if (!onPress && !onRelease) me.unregister(key);
callbacks[toCharCode(key)] = [onPress, onRelease];
But where does `callbacks' come from?
return arguments.caller;
You are confused.
}
// or //
this.register = function (key, onPress, onRelease) {
if (!initted) init();
if (typeof key == 'array') {
You are *very* confused.
^^^for (int i=key.length, i--
Is this supposed to be JScript .NET, AFAIK only available server-side, or
are you only incompetent instead?
[...]You don't know what you are talking about. Incidentally, not even the
crappy jQuery promotes this ridiculous pattern, the chaining there goes
$(...).method(...).method(...) instead (which is only slightly less
inefficient, error-prone and hard to debug).
I don't know what you are talking about
That much is obvious.
PointedEars