vargetSingle=function(fn){varresult=null;returnfunction(){returnresult||(result=fn.apply(this,arguments));//這行}}//使用varfoo=getSingle(function(){//do...})foo()這個(gè)單例的代碼中。(result=fn.apply(this,arguments))改成result=fn()是不是也行?為什么一定要用apply修正一下this呢?感覺這里的this即使不修正,也是指向宿主window。麻煩大佬們幫忙指導(dǎo)下,謝謝。
JavaScript中的apply在這里到底修正了什么
狐的傳說
2019-05-06 21:42:32