Skip to content

Instantly share code, notes, and snippets.

@rrameshbtech
Last active November 17, 2018 02:13
Show Gist options
  • Save rrameshbtech/debdd681ab940ff7cfaf94487953dd8a to your computer and use it in GitHub Desktop.
Save rrameshbtech/debdd681ab940ff7cfaf94487953dd8a 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;
};
document.write(getSpeciality.call(siliconVallyOfIndia)); // Bengaluru is known for software industries
document.write('<br>');
document.write(getSpeciality.apply(texCity)); // Tiruppur is known for textile industries
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<!--<link rel="stylesheet" href="styles.css">-->
</head>
<body>
<h1>Hello world!</h1>
<script src="explicit-binding-this.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment