On Saturday, February 15, 2014 10:54:13 PM UTC+1, rjcarr wrote:
>
> Thanks for the explanation and examples. I actually know javascript quite
> well, including the ramifications of using this inside of closures, but as
> I said, I didn't know that $entry was setting up a closure.
>
It's not. It's taking a function as argument and returns a function. If you
pass your 'y.bar' (to keep my pure-JS example) as argument, it'll
ultimately be called just like my "var foo", and depending on the 'this' at
the time of the call, it'll fail.
So you *have* to create a closure to bind 'bar' to 'y' (and pass that
function to $entry), or you could use $entry(y.bar.bind(y)) which would be
equivalent (but IE9+).
$entry basically is:
function $entry(f) {
return function() {
try {
run_entry_commands(); // see Scheduler#scheduleEntry
try {
f.apply(this, arguments);
} finally {
run_finally_commands(); // see Scheduler#scheduleFinally
}
} catch (e) {
reportUncaughtException(e); // see GWT#reportUncaughtException
}
};
}
which, for the purpose of the example/demo, could be simplified as:
function $entry(f) {
return function() { f.call(this, arguments); }
}
or even
function $entry(f) { return f; }
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.