Open jeremy50dj opened 9 years ago
Edit Watch this page this (computer programming) this, self, and Me are keywords used in some computer programming languages to refer to the object, class, or other entity that the currently running code is part of. The entity referred to by these keywords thus depends on the execution context (such as which object is having its method called). Different programming languages use these keywords in slightly different ways. In languages where a keyword like "this" is mandatory, the keyword is the only way to access data and methods stored in the current object. Where optional, they can disambiguate variables and functions with the same name.
Object-oriented programming Edit
In many object-oriented programming languages, this (also called self or Me) is a variable that is used in instance methods to refer to the object on which they are working. C++ and languages which derive in style from it (such as Java, C#, D, and PHP) generally use this. Smalltalk and others, such as Object Pascal, Perl, Python, Ruby, Objective-C, and Swift, use self. Microsoft's Visual Basic uses Me.
The concept is similar in all languages: this is usually an immutable reference or pointer which refers to the current object; the current object often being the code that acts as 'parent' to the property, method, sub-routine or function that contains the this keyword. After an object is properly constructed, or instantiated, this is always a valid reference. Some languages require it explicitly; others use lexical scoping to use it implicitly to make symbols within their class visible. Or alternatively, the current object referred to by this may be an independent code object that has called the function or method containing the keyword this. Such a thing happens, for example, when a Javascript event handler attached to an HTML tag in a web page calls a function containing the keyword this stored in the global space outside the document object; in that context, this will refer to the page element within the document object, not the enclosing window object.[1]
In some languages, for example C++ and Java, this or self is a keyword, and the variable automatically exists in instance methods. In others, for example Python and Perl 5, the first parameter of an instance method is such a reference. It needs to be specified explicitly. In that case, the parameter need not necessarily be named this or self; it can be named freely by the programmer like any other parameter. However, by informal convention, the first parameter of an instance method in Perl or Python is named self.
Static methods in C++ or Java are not associated with instances but classes, and so cannot use this, because there is no object. In other languages, such as Python, Ruby, Smalltalk, Objective-C, or Swift, the method is associated with a class object that is passed as this, and they are called class methods.
Subtleties and difficulties
Implementations
See also
References
Further reading
External links
Read in another language Last edited 1 month ago by Widefox
AddThis MY SITEANALYTICSTOOLSGET THE CODEProfile Photo
× NOTIFICATIONS × Get The Code
Follow the instructions below to install tools on your site
HTML WEBSITE WORDPRESS TUMBLR SHOPIFY MAGENTO First copy the following code.
Secondly, paste the above code right above the closing
of the HTML in your website on every page you want AddThis to work.
It should be right before the closing body tag.
Paste Here
https://en.m.wikipedia.org/wiki/This_(computer_programming)