Monday, February 29, 2016

JavaScript Bind

Ex 1

var a = {name:"bob"};
var b = {name: "john"};
function showName(){return this.name;};
showName.bind(a)();
showName.bind(b)();

Ex 2

function add(x,y){

return x + y;
}

var plus1 = add.bind(null,1);
console.log(plus1(5));



1 comment:

  1. https://www.smashingmagazine.com/2014/01/understanding-javascript-function-prototype-bind/

    ReplyDelete