做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

javascriptcreateAdder函數(shù)功能與使用說明_javascript技巧

來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 20:49:47
文檔

javascriptcreateAdder函數(shù)功能與使用說明_javascript技巧

javascriptcreateAdder函數(shù)功能與使用說明_javascript技巧:英文原文 createAdder(x) is a function that returns a function. In JavaScript, functions are first-class objects: they can be passed to other functions as arguments and returned from
推薦度:
導(dǎo)讀javascriptcreateAdder函數(shù)功能與使用說明_javascript技巧:英文原文 createAdder(x) is a function that returns a function. In JavaScript, functions are first-class objects: they can be passed to other functions as arguments and returned from

英文原文
createAdder(x) is a function that returns a function. In JavaScript, functions are first-class objects: they can be passed to other functions as arguments and returned from functions as well. In this case, the function returned is itself a function that takes an argument and adds something to it.

Here’s the magic: the function returned by createAdder() is a closure. It “remembers” the environment in which it was created. If you pass createAdder the integer 3, you get back a function that will add 3 to its argument. If you pass 4, you get back a function that adds 4. The addThree and addFour functions in the above example are created in this way.

Let’s take another look at the addLoadEvent function. It takes as its argument a callback function which you wish to be executed once the page has loaded. There follow two cases: in the first case, window.onload does not already have a function assigned to it, so the function simply assigns the callback to window.onload. The second case is where the closure comes in: window.onload has already had something assigned to it. This previously assigned function is first saved in a variable called oldonload. Then a brand new function is created which first executes oldonload, then executes the new callback function. This new function is assigned to window.onload. Thanks to the magical property of closures, it will “remember” what the initial onload function was. Further more, you can call the addLoadEvent function multiple times with different arguments and it will build up a chain of functions, making sure that everything will be executed when the page loads no matter how many callbacks you have added.

Closures are a very powerful language feature but can take some getting used to. This article on Wikipedia provides more in-depth coverage.

中文翻譯:有更好的可以留言。大體意思差不多了

createAdder(x)是一個(gè)函數(shù),返回一個(gè)函數(shù)。在JavaScript中,函數(shù)是第一類對(duì)象:另外它們可以被傳遞到其他函數(shù)作為參數(shù)和函數(shù)返回。在這種情況下,函數(shù)返回本身就是一個(gè)函數(shù)接受一個(gè)參數(shù),并增加了一些東西。

在這里,Äôs the magic:由createAdder返回函數(shù)()是一個(gè)閉包。它,Äúremembers,非盟在創(chuàng)建它的環(huán)境。如果傳遞createAdder整數(shù)3,你回來一個(gè)函數(shù),將增加3至其參數(shù)。如果你通過四,你回來一個(gè)函數(shù),增加了4。該addThree在上面的例子addFour職能創(chuàng)造這樣的。

讓,星光大道可以再一次看看addLoadEvent功能。這需要將執(zhí)行一次頁面已加載為一個(gè)回調(diào)函數(shù)的參數(shù),你的愿望。有下列兩種情況:在第一種情況,在window.onload已經(jīng)沒有分配給它一個(gè)函數(shù),因此函數(shù)簡單的回調(diào)在window.onload分配。第二個(gè)案例是在關(guān)閉的時(shí)候:在window.onload已經(jīng)有分配給它的東西。這是以前分配的功能首次在一個(gè)名為oldonload變量保存。然后,一個(gè)全新的功能是創(chuàng)建的第一個(gè)執(zhí)行oldonload,然后執(zhí)行新的回調(diào)函數(shù)。這一新功能被分配在window.onload。神奇的封鎖財(cái)產(chǎn)感謝,它會(huì)Äúremember,非盟最初的onload什么功能。進(jìn)一步,你可以調(diào)用函數(shù)的addLoadEvent多次與不同的參數(shù),它會(huì)建立一個(gè)職能鏈,確保一切都將在頁面加載時(shí)執(zhí)行,不管你有多少回調(diào)增加。

閉包是一個(gè)非常強(qiáng)大的語言功能,但可能需要一些時(shí)間來適應(yīng)。這種對(duì)維基百科的文章提供了更深入的報(bào)道。

核心代碼
代碼如下:
function createAdder(x) {
return function(y) {
return y + x;
}
}
addThree = createAdder(3);
addFour = createAdder(4);
document.write('10 + 3 is ' + addThree(10) + '
');
document.write('10 + 4 is ' + addFour(10));
document.write('-10 + 4 is ' + addFour(-10));

演示代碼:

[Ctrl+A 全選 注:如需引入外部Js需刷新才能執(zhí)行]

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

javascriptcreateAdder函數(shù)功能與使用說明_javascript技巧

javascriptcreateAdder函數(shù)功能與使用說明_javascript技巧:英文原文 createAdder(x) is a function that returns a function. In JavaScript, functions are first-class objects: they can be passed to other functions as arguments and returned from
推薦度:
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top 主站蜘蛛池模板: 庆城县| 新丰县| 图木舒克市| 两当县| 衡东县| 东海县| 平乡县| 新竹市| 瑞安市| 聊城市| 揭东县| 广水市| 鄢陵县| 益阳市| 黄冈市| 祁东县| 莱阳市| 庆元县| 东海县| 同仁县| 甘德县| 南木林县| 平安县| 弥勒县| 新龙县| 城口县| 永兴县| 肥乡县| 广南县| 信阳市| 新竹县| 泸溪县| 深水埗区| 邵东县| 宜川县| 遂平县| 涿州市| 濮阳市| 会东县| 嫩江县| 长武县|