javascript - About the usage of call() function
欧阳克
欧阳克 2017-06-28 09:24:04
0
2
726

I see many people using the call function when calling other functions. I think this looks simple and makes it difficult for a novice like me to understand.
The following example is to realize that the results returned by fn and result are the same, that is, str1 and str2 are returned. The results of the following two methods are the same.
Could you please tell me that call is generally used in addition to binding objects? Under what circumstances, the problem may not be described clearly. Please forgive me.
1.

function func(fn,str1){
    return result = function (str2){
        return fn.call(this,str1,str2)
}

//这种方式我自己可以明白 fn获得他的父级函数fnc返回的str1+str2字符串,自己再返回出来
2.function func(fn,str1){
    return result = function (str2){
        return str1+str2
    }
    fn(func(null,str1,str2))
}
欧阳克
欧阳克

温故而知新,可以为师矣。 博客:www.ouyangke.com

reply all(2)
三叔

MDN - Function.prototype.call()

学习ing

In fact, I really want to say that things like this, call, apply, bind, and new are the cornerstones of js and must be mastered by everyone who wants to become a front-end engineer. At the same time, these things are also more brain-burning in js and difficult to master. Yes, I need to read two more books and write more demos. To explain this clearly, I can write a long article. If you have the patience to read it, I suggest you read a book.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template