خرید بک لینک
Hey guys,
I'm trying to learn how to use call, and I think I got it, but I don't understand why it's important. Here's a code I wrote without using code:

Code:

var haveri = {num: 2};

function Add(a,b) {
  return b.num+a;
}
console.log(Add(3, haveri));

And it's possible to write the same thing with call:

Code:

var haveri = {num: 2};

function Add(a) {
 return this.num+a;
}
console.log(Add.call(haveri,3));

So why do you need to use call, if you can just call the variable as an argument inside the function?
Thanks in advance!
I'm obviously missing something simple here...

برچسب: نویسنده: آیلین رضوانی تاريخ: پنجشنبه 2 شهريور 1396 ساعت: 23:38

صفحه بندی