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

Save access to this scope

Explanation of the problem this changed The value of thisMDN has changed and is no longer referencing the expected element or value. Often this is because the scope has changed, and as a result so has the this reference. this is contained in an execution context The scope refers to the current Execution ContextECMA. In … Read more

std::shared_ptr of this

There is std::enable_shared_from_this just for this purpose. You inherit from it and you can call .shared_from_this() from inside the class. Also, you are creating circular dependencies here that can lead to resource leaks. That can be resolved with the use of std::weak_ptr. So your code might look like this (assuming children rely on existence of … 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

‘this’ does not work properly in another event. I’m clueless as to why [duplicate]

You aren’t attaching the event handler correctly. This line: $(‘.figure’).click(toggleCarousel(this)); …is calling toggleCarousel with this immediately (that’s what the parens will do). What you really want is to pass the function object to .click(): $(‘.figure’).click(toggleCarousel); Update: As @FelixKling pointed out, you’ll also want to pass the target of the event to the downstream functions; it … Read more