User Tools

Site Tools


jsfn:understanding_call-and-apply_invocation

This is an old revision of the document!


Call & Apply (indirect invocation)

  1. permet de définir la valeur de l'argument this
  2. Control: this and arguments
  3. Call passe une valeur, Apply un array
var speak = function (what) {
  console.log(this.love)
}
var saySomething = {normal: "meow", love: "purr"} // ça pourrait être des fonctions en attributs
speak.call(saySomething); // purr
var speak = function (what) {
  console.log(what)
}
var saySomething = {normal: "meow", love: "purr"}
speak.call(saySomething, saySomething.normal); // le deuxième argument va devenir le what plus haut ! // meow 

var speak = function (what) {

console.log(what)
console.log(this.love)

} var saySomething = {normal: “meow”, love: “purr”} ça pourrait être des fonctions en attributs speak.apply(saySomething, [“meouff”]); meouff, purr </code>

jsfn/understanding_call-and-apply_invocation.1453934474.txt.gz · Last modified: 2016/01/27 23:41 by leo