Using “this” with class name

Usually, you can use only this. But, sometimes this makes reference to an inner class… so, for example: Button button = (Button)findViewById(R.id.ticket_details_sell_ticket); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // it will be wrong to use only “this”, because it would // reference the just created OnClickListener object Intent login = new Intent(ClassName.this, … Read more

Why does String.prototype log it’s object like a standard object, while Array.prototype logs it’s object like a standard array?

Because in a method call the this argument is always (in sloppy mode) casted to an object. What you see is a String object, which was produced from the “test” primitive string value. The array on which you call your method is already an object, so nothing happens and you just get the array as … 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

Use of “this” keyword in C++ [duplicate]

Yes, it is not required and is usually omitted. It might be required for accessing variables after they have been overridden in the scope though: Person::Person() { int age; this->age = 1; } Also, this: Person::Person(int _age) { age = _age; } It is pretty bad style; if you need an initializer with the same … Read more