this

  • this
    • this is used inside a function (let’s say function A) and it contains the value of the object that invokes function A.
    • this is not assigned a value until an object invokes the function where this is defined
  • sample
    • var person = {
      firstName :”Penelope”,
      lastName :”Barrymore”,
      // Since the “this” keyword is used inside the showFullName method below, and the showFullName method is defined on the person object,
      // “this” will have the value of the person object because the person object will invoke showFullName ()
      showFullName:function () {
      console.log (this.firstName + ” ” + this.lastName);
      }

      }

      person.showFullName (); // Penelope Barrymore

Advertisements
This entry was posted in JavaScript. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s