Javascript función 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"

view raw

JS_call.js

hosted with ❤ by GitHub

Deja un comentario

Este sitio utiliza Akismet para reducir el spam. Conoce cómo se procesan los datos de tus comentarios.