andibra10
10/12/2018 - 11:23 PM

call.js

// EXEMPLO 1
var chat = function(name, message){
  console.log(name + ' said: '+ message); // fulano said: how are you?
}
chat.call({}, 'fulano', 'How are you?');

// 1º argumento é o contexto this
// 2º argumento é o nome
// 3º argumento é a mensagem

//EXEMPLO 2
var say = { said : 'I am fine thanks, and you?' };
function talk(){
    console.log(this.said);
}
talk.call(say);