Javascript Practice Day 6 : Understanding Call,Apply,Bind

//Call Apply and Bind

//while wroking with object in javascript each one will have it onw properties (methods and variables) , So with Call ,Apply and Bind we can make //the methods share among each other .


//creating  an object

var obj1 ={ num : 2, num2 :3 };

var func=function(a,b,c){
    return this.num+this.num2+a+b+c;
}

var arr=[1,2,3];
    
console.log(func.call(obj1,1,2,3));
console.log(func.apply(obj1,arr));
var bound=func.bind(obj1)
console.log(bound(1,2,3));

Comments

Popular posts from this blog

Authentication and Authorization in Web API -Part1

My Gardening Journey 6