-4

what is 'this' keyword and what's its functions?

  • 10
    java or javascript? – Adam Sep 03 '10 at 16:09
  • 4
    The pity upvote is atrocious, whoever cast it. Remember that when you upvote, you're saying "this question is useful and clear". It's neither. – Andy E Sep 03 '10 at 16:15
  • this == homework, there's no way it could not be. @vikash: Please do not post questions (especially homework!) without showing that you have put some effort into them. – Tomalak Sep 03 '10 at 16:15

4 Answers4

3

The this keyword refers to the current object in the context in which the keyword appears.

Here's an article with more: http://www.quirksmode.org/js/this.html

FrustratedWithFormsDesigner
  • 26,726
  • 31
  • 139
  • 202
1

In Java this refers to the object you are currently in. See http://download.oracle.com/javase/tutorial/java/javaOO/thiskey.html

In JavaScript that is true as well, but in a function it can mean the "owner" of a function or the global object (ie window). See http://www.quirksmode.org/js/this.html

Adam
  • 43,763
  • 16
  • 104
  • 144
0

The this refers as to the object you are currently in. For example, if your object has a method called doSomething(), you could call the method , from another method in your class by doing:

this.doSomething();

Hope this helps.

Live
  • 1,981
  • 16
  • 17
0

this refers to the current object, so its methods are those defined by the class that the current object is an instance of.

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166