When to call activity context OR application context?

getApplicationContext() is almost always wrong. Ms. Hackborn (among others) have been very explicit that you only use getApplicationContext() when you know why you are using getApplicationContext() and only when you need to use getApplicationContext(). To be blunt, “some programmers” use getApplicationContext() (or getBaseContext(), to a lesser extent) because their Java experience is limited. They implement … Read more

Pass correct “this” context to setTimeout callback?

EDIT: In summary, back in 2010 when this question was asked the most common way to solve this problem was to save a reference to the context where the setTimeout function call is made, because setTimeout executes the function with this pointing to the global object: var that = this; if (this.options.destroyOnHide) { setTimeout(function(){ that.tip.destroy() … Read more

Use of “this” keyword in formal parameters for static methods in C#

This is an extension method. See here for an explanation. Extension methods allow developers to add new methods to the public contract of an existing CLR type, without having to sub-class it or recompile the original type. Extension Methods help blend the flexibility of “duck typing” support popular within dynamic languages today with the performance … Read more

What does ‘var that = this;’ mean in JavaScript?

I’m going to begin this answer with an illustration: var colours = [‘red’, ‘green’, ‘blue’]; document.getElementById(‘element’).addEventListener(‘click’, function() { // this is a reference to the element clicked on var that = this; colours.forEach(function() { // this is undefined // that is a reference to the element clicked on }); }); My answer originally demonstrated this … Read more

Difference between getContext() , getApplicationContext() , getBaseContext() and “this”

View.getContext(): Returns the context the view is currently running in. Usually the currently active Activity. Activity.getApplicationContext(): Returns the context for the entire application (the process all the Activities are running inside of). Use this instead of the current Activity context if you need a context tied to the lifecycle of the entire application, not just … Read more

Use of ‘prototype’ vs. ‘this’ in JavaScript?

The examples have very different outcomes. Before looking at the differences, the following should be noted: A constructor’s prototype provides a way to share methods and values among instances via the instance’s private [[Prototype]] property. A function’s this is set by how the function is called or by the use of bind (not discussed here). … Read more

How does the “this” keyword work, and when should it be used?

this is a keyword in JavaScript that is a property of an execution context. Its main use is in functions and constructors. The rules for this are quite simple (if you stick to best practices). Technical description of this in the specification The ECMAScript standard defines this via the abstract operation (abbreviated AO) ResolveThisBinding: The … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)