The "this" keyword: Introduction and Implicit Binding

Share this video with your friends

Send Tweet

In this lesson we introduce the "this" keyword in JavaScript as well as talk about "implicit binding" or the first rule in discovering what the "this" keyword is referencing.

Lucas
Lucas
~ 5 years ago

I tried doing the exact code you did, but it returns 'undefined', why?

var sayNameMixin = function(obj){
  obj.sayName = function(){
    console.log(this.name);
  };
};
var me = {
  name: 'Tyler',
  age: 25
};
var you = {
  name: 'Joey',
  age: 21
};

sayNameMixin(me);