Animations

API

Arrays

Async

Basics

Challenges

Classes

Console

Dates

Debugging

DOM Elements

DOM Methods

DOM Navigation

DOM Properties

Event Listeners

Flow Control

Forms

Functions

Global Functions

JSON

Keywords

Libraries (3rd party)

Math

Modules

Objects

Snippets

String

Types

Widgets

Window Object

JavaScript - This

In JavaScript, the thing called this, is the object that "owns" the JavaScript code. The value of this, when used in a function, is the object that "owns" the function. This can be another object.

Note that this is not a variable. It is a keyword. You cannot change the value of this.

In most cases, the value of this is determined by how a function is called. It can't be set by assignment during execution, and it may be different each time the function is called.

Another way of thinking about this is that this often refers to a Class's members.

http://javascriptissexy.com/understand-javascripts-this-with-clarity-and-master-it/



var person =
{
    FirstName: "Penelope",
    LastName: "Barrymore",
    FullName: function ()
    {
        return this.FirstName + " " + this.LastName;

        // We could have also written this:​​
        // console.log(person.firstName + " " + person.lastName);
    }
}

let demo1 = document.getElementById("demo1");
demo1.innerHTML = person.FullName();