Saturday, June 16, 2018

JavaScript - Object - this - bind

Below code demonstrates the usage of this and bind when dealing with objects:

// here this refers to the window object
function myFunc(){
  console.log(this);
}

//myFunc();

var obj = {
  objectFunction:myFunc
};

var Person = {
  name: "Cassandra",
  age: 27
}

obj.objectFunction.bind(Person)();

Refer:



Practice at:
http://jsbin.com

No comments:

Post a Comment