Skip to content

Instantly share code, notes, and snippets.

@rrameshbtech
Last active July 30, 2018 09:21
Show Gist options
  • Save rrameshbtech/1e8418e3fd91a41280bef5405103d375 to your computer and use it in GitHub Desktop.
Save rrameshbtech/1e8418e3fd91a41280bef5405103d375 to your computer and use it in GitHub Desktop.
Explicit binding of this using call & apply
const siliconVallyOfIndia = {
city: 'Bengaluru',
speciality: 'software industries'
};
const texCity = {
city: 'Tiruppur',
speciality: 'textile industries'
};
const getSpeciality = function() {
return this.city + ' is known for ' + this.speciality;
};
console.log(getSpeciality.call(siliconVallyOfIndia)); // Bengaluru is known for software industries
console.log(getSpeciality.apply(texCity)); // Tiruppur is known for textile industries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment