在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ 【基礎(chǔ)疑惑】為什么要在方法的最后加上逗號(hào)后再寫(xiě)上參數(shù)?

【基礎(chǔ)疑惑】為什么要在方法的最后加上逗號(hào)后再寫(xiě)上參數(shù)?

疑問(wèn)在于最后一行,為啥要加上前面一堆參數(shù)?百度了好久沒(méi)找到答案,因?yàn)椴磺宄@種叫什么術(shù)語(yǔ)。
代碼如下:

    for(let i=1;i<61;i++){
        const info_sel = '#ajax_loading_con > li:nth-child(' + i + ')';
        const name_sel = '#ajax_loading_con > li:nth-child(' + i + ') > a.info';
        const icon_sel = '#ajax_loading_con > li:nth-child(' + i + ') > a.info > img';
        const href_sel = '#ajax_loading_con > li:nth-child(' + i + ') > a.info';

        //MapReduce方式
        const games = await page.evaluate((gInfo, gName, gIcon, gHref) => {
            return Array.prototype.slice.apply(document.querySelectorAll(gInfo))
                .map(document => {
                    const gameName = document.querySelector(gName).title;
                    const gameIcon = document.querySelector(gIcon).src;
                    const gameHref = document.querySelector(gHref).href;
                    return {
                        gameName,
                        gameIcon,
                        gameHref,
                    };
                })
        }, info_sel, name_sel, icon_sel, href_sel);
回答
編輯回答
氕氘氚

整理一下你可能就看明白了:


let mapper = (gInfo, gName, gIcon, gHref) => {
    return Array.prototype.slice.apply(document.querySelectorAll(gInfo))
        .map(document => {
            const gameName = document.querySelector(gName).title;
            const gameIcon = document.querySelector(gIcon).src;
            const gameHref = document.querySelector(gHref).href;
            return {
                gameName,
                gameIcon,
                gameHref,
            };
        })
};

const games = await page.evaluate(mapper, info_sel, name_sel, icon_sel, href_sel);

javascript 里支持接收一個(gè)函數(shù)作為參數(shù)。

2018年5月13日 13:11