Skip to content

Instantly share code, notes, and snippets.

@moisescastillo

moisescastillo/JS_call.js

Last active Jul 11, 2020
Embed
What would you like to do?
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