What is the ‘this’ pointer?

this refers to the current object. The keyword this identifies a special type of pointer. Suppose that you create an object named x of class A, and class A has a non-static member function f(). If you call the function x.f(), the keyword this in the body of f() stores the address of x.

Java leaking this in constructor [duplicate]

Leaking the this reference in the constructor (not controller) is dangerous, especially in a multithreaded environment. This is because the object is not fully constructed until the constructor call finishes. Leaking this from the constructor thus means that the external world gets access to an object which is not yet fully constructed. This may not … Read more

this inside function

The this keyword refers to the object the function belongs to, or the window object if the function belongs to no object. It’s used in OOP code, to refer to the class/object the function belongs to For example: function foo() { this.value=”Hello, world”; this.bar = function() { alert(this.value); } } var inst = new foo(); … Read more

difference and when to use getApplication(), getApplicationContext(), getBaseContext() and someClass.this

Toast and Intent, both requires reference to context. And getApplication, getApplicationContext, LoginActivity.this and getBaseContext, they all offer reference to the context. Now the thing confuses is the declaration of different contexts and their specific-usage. To make things simple, you should count two types of context available in the Android framework. Application Context Activity Context Application … Read more

Difference between $(this) and event.target?

There is a difference between $(this) and event.target, and quite a significant one. While this (or event.currentTarget, see below) always refers to the DOM element the listener was attached to, event.target is the actual DOM element that was clicked. Remember that due to event bubbling, if you have <div class=”outer”> <div class=”inner”></div> </div> and attach … Read more