最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

当前代码需要IIFE(自调用)

IT培训 admin 3浏览 0评论

当前代码需要IIFE(自调用)

我目前对如何使代码IIFE自我调用感到困惑。问题陈述是:

您的客户希望从一个邮政编码研究(每个列表仅列出一次)中按从小到大的顺序列出一个邮政编码列表。他希望它“自动运行”(自动调用)。

我的代码显示的是正确的输出,所有邮政编码从最小到最大都列出一次。我需要帮助来了解如何使当前代码成为“自调用”代码。这是我当前的代码:

//Start.
window.onload = uniqueZipcodes;
function assignment12_3() {
    // Your code goes in here.
}

function uniqueZipcodes(){

    //Start.
    //Variables
    var records, zip;
    var output = document.getElementById("selfInvokingFunctionDiv");
    var zipcodes = [];
    var outputString = "";

    //Gets the records...
    records = openZipCodeStudyRecordSet();
    //This will loop through the records and put unique records
    //into an array
    while(records.readNextRecord()){
        zip = records.getSampleZipCode();
        if(!zipcodes.includes(zip)){
            zipcodes.push(zip);
        }
    }

    //Will sort the zipcodes
    zipcodes.sort();

    //outputs the zipcodes.
    for(var z in zipcodes){
        outputString += zipcodes[z] + "</br>";
    }

    outputDiv.innerHTML += outputString;
};
回答如下:

当前代码需要IIFE(自调用)

我目前对如何使代码IIFE自我调用感到困惑。问题陈述是:

您的客户希望从一个邮政编码研究(每个列表仅列出一次)中按从小到大的顺序列出一个邮政编码列表。他希望它“自动运行”(自动调用)。

我的代码显示的是正确的输出,所有邮政编码从最小到最大都列出一次。我需要帮助来了解如何使当前代码成为“自调用”代码。这是我当前的代码:

//Start.
window.onload = uniqueZipcodes;
function assignment12_3() {
    // Your code goes in here.
}

function uniqueZipcodes(){

    //Start.
    //Variables
    var records, zip;
    var output = document.getElementById("selfInvokingFunctionDiv");
    var zipcodes = [];
    var outputString = "";

    //Gets the records...
    records = openZipCodeStudyRecordSet();
    //This will loop through the records and put unique records
    //into an array
    while(records.readNextRecord()){
        zip = records.getSampleZipCode();
        if(!zipcodes.includes(zip)){
            zipcodes.push(zip);
        }
    }

    //Will sort the zipcodes
    zipcodes.sort();

    //outputs the zipcodes.
    for(var z in zipcodes){
        outputString += zipcodes[z] + "</br>";
    }

    outputDiv.innerHTML += outputString;
};
回答如下:

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论