JavaScript object functions and `this` when unbound and returned in expression/parens

The grouping operator does not destroy property references, which are provoking the method call. This is explicitly mentioned in the spec: NOTE: This algorithm does not apply GetValue to the result of evaluating Expression. The principal motivation for this is so that operators such as delete and typeof may be applied to parenthesised expressions. In … Read more

How to reference the caller object (“this”) using attachEvent

From this quirksmode article with regard to attachEvent: Events always bubble, no capturing possibility. The event handling function is referenced, not copied, so the this keyword always refers to the window and is completely useless. The result of these two weaknesses is that when an event bubbles up it is impossible to know which HTML … Read more

Java: Class.this

LocalScreen.this refers to this of the enclosing class. This example should explain it: public class LocalScreen { public void method() { new Runnable() { public void run() { // Prints “An anonymous Runnable” System.out.println(this.toString()); // Prints “A LocalScreen object” System.out.println(LocalScreen.this.toString()); // Won’t compile! ‘this’ is a Runnable! onMake(this); // Compiles! Refers to enclosing object onMake(LocalScreen.this); … Read more

requestAnimationFrame with this keyword

I’m trying to pass display.draw which is the function in which webkitRequestAnimationFram resides. webkitRequestAnimationFrame will presumably call the function you pass in, something like this: function webkitRequestAnimationFrame(callback) { // stuff… callback(); // other stuff… } At this point, you have dissociated (detached) the draw function from its invocation context. You need to bind the function … Read more