Javascript Function Execution Context Change via apply()

Description

Javascript Function Execution Context Change via apply()



let person = {// w  w w . ja va 2  s.c o  m
  name: "Daniel",
  age: 12,
  weight: "150lb",
  describe: function(useLongDesc) {
    console.log("Person's name: " + this.name);
    console.log("Person's age: " + this.age);    
    if (useLongDesc == true) {
      console.log("Person's weight: " + this.weight);  
    }
  }
}

let jamesBond = {
  name: "James, James bond.",
  age: "timeless",
  weight: "enough"
}

person.describe.apply(jamesBond, [true]);



PreviousNext

Related