In many object-oriented languages, "this" is a reference to the current instance of the class or object. Use with a language tag, like [javascript], [java], [c#], etc.
this
is a keyword that refers to the current class instance or object in many object-oriented programming languages.
For example in Java:
class ExampleClass{
private String name = 'Example';
public ExampleClass(String name){
// refer to the name property of this instance
this.name = name;
this.initialize();
}
public void initialize(){
// do something here
}
}
Common questions about the keyword involve the somewhat confusing rules Javascript uses. There are instances in Javascript where the this
context can be lost.
Some programming languages use variants of the this
keyword, such as Me
in Visual Basic and self
in Python and Ruby.
See also:
http://en.wikipedia.org/wiki/This_%28computer_programming%29