Using this Value

The "this object" denotes the "the current object". In the previous example, the method sayName() used hero.name to access the name property of the hero object. When you're inside a method, there is another way to access the object by using the reserved value this.

snippet
var hero = {
    name: 'Rafaelo',
    sayName: function() {
        return this.name;
    }
}
hero.sayName();

"Rafaelo"
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +