Skip to content

Instantly share code, notes, and snippets.

@moisescastillo
Last active July 11, 2020 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moisescastillo/02e0c3042ce26cc2a65221c63534b9fa to your computer and use it in GitHub Desktop.
Save moisescastillo/02e0c3042ce26cc2a65221c63534b9fa to your computer and use it in GitHub Desktop.
JavaScript Function Call
// JavaScript Function Call
let person = {
bio: function() {
return `Name: ${this.name}, Age: ${this.age}`;
}
}
function greeting(message) {
return `${this.name} : ${message}`;
}
let person1 = {name: 'John', age: 23};
let person2 = {name: 'Doe', age: 31};
console.log(greeting.call(person1,'Hello'));
// -> "John : Hello"
console.log(greeting.call(person2,'Bye'));
// -> "Doe : Bye"
console.log(person.bio.call(person1));
// -> "Name: John, Age: 23"
console.log(person.bio.call(person2));
// -> "Name: Doe, Age: 31"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment