lunes, 16 de marzo de 2015

Invacando funciones con call y apply

Call

var speak = function(what) {
  console.log(what);

}

var saySomething = {normal: "meow", love: "purr"}
speak.call(saySomething, saySomething.normal);

Apply


var speak = function(what) {
  console.log(what);
  console.log(this.love);
}

var saySomething = {normal: "meow", love: "purr"}
speak.apply(saySomething, ['meouff']);

No hay comentarios:

Publicar un comentario