using 'this'

by fredericklim

JavaScript

function makeUser() {
  return {
    name: "John",
    //ref: function () {return this;}
    ref: function() {return this;}
  };
}

let user = makeUser();

alert( user.ref().name );

let usera = {
  firstName: "Ilya",
  sayHi() {
    //let arrow = () => alert(this.firstName);
    function arrow() { alert(this.firstName);}
    arrow();
  }
};

usera.sayHi(); // Ilya