working link=>
https://stackblitz.com/edit/js-nntys1
https://stackblitz.com/edit/js-nntys1
//here is a small ployfill of bind method.....................
var myObject=
{
name:"manish",
age:22
}
function showName(engg,sal)
{
console.log("my name is "+this.name+" and my age is"+" "+this.age+" "+"and i work as a engg "+engg+" "+"and my salary is "+sal);
}
const a=showName.bind(myObject,"software",20000);
a();
console.log("mybind starts from here...............>>>>")
Function.prototype.myBind=function()
{
var thisFunction=this;
var obj=arguments[0];
if(typeof obj!="object")
{
throw new Error("bind method required a object");
}
var args=[];
for(var i=1;i<arguments.length;i++)
{
args.push(arguments[i]);
}
return function()
{
thisFunction.apply(obj,args)
}
}
const b=showName.myBind(myObject,"software",20000);
b();
Comments
Post a Comment