欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Function.prototype.call.apply結(jié)合用法分析示例

 更新時(shí)間:2013年07月03日 15:12:53   作者:  
昨天在網(wǎng)上看到一個(gè)很有意思的js面試題:var a = Function.prototype.call.apply(function(a){return a;}, [0,4,3]);alert(a); 分析步驟如下,感興趣的朋友可以參考下哈
昨天在網(wǎng)上看到一個(gè)很有意思的js面試題,就跟同事討論了下,發(fā)現(xiàn)剛開始很繞最后豁然開朗,明白過來之后發(fā)現(xiàn)還是挺簡(jiǎn)單的,跟大家分享下!
題目如下:var a = Function.prototype.call.apply(function(a){return a;}, [0,4,3]);alert(a);

分析步驟如下:
1、將Function.prototype.call當(dāng)成整體,call方法是由瀏覽器實(shí)現(xiàn)的本地方法,是函數(shù)類型的內(nèi)部方法
var a = (Function.prototype.call).apply(function(a){return a;}, [0,4,3]);

2、fun.apply(obj,args)等價(jià)于obj.fun(args),這一步是重點(diǎn),必須理解!
(function(a){return a;}).apply(0,[4,3])
(function(a){return a;}).call(0,4,3)

3、 到這步結(jié)果就很明顯了,a就是4,alert的結(jié)果就是4

這個(gè)題目迷惑的點(diǎn)就在于Function.prototype.call,理解好了,就清晰明了了!

相關(guān)文章

最新評(píng)論