Sorry, I wrote that up and then it disappeared during editing.  The way
I expected foo.bar() to work is that "foo.bar" would give you a closure
specifying this=foo.  JavaScript is full of creative approaches,
however.  The way it actually works is that JavaScript looks at the
syntax of foo.bar and determines that "foo" should be the this value.
For (null,foo.bar), it sees a different syntax and makes a different
decision.

I don't understand the full set of rules, but they should be findable by
tracing backward from section 11.2.3 in this spec:

http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf

Here's a sample program showing two cases:

function showthis() {
  window.alert("this = " + this);
}

var obj = {
  m : showthis,
  toString : function() { return "obj" }
};

obj.m();  // shows "this = obj"
(null, obj.m)();  // shows "this = [object DOMWindow]"


http://gwt-code-reviews.appspot.com/132815
-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to