gpt4 book ai didi

javascript - 用另一个函数修改一个函数的私有(private)变量

转载 作者:行者123 更新时间:2023-12-03 09:06:17 25 4
gpt4 key购买 nike

给定以下函数:

function countdown() {
var result = "";

// do something with the result variable

return result;
}

在调用倒计时函数之前,如何从另一个函数内更新 result 变量?

function something(){
// update private variable "result"
}

最佳答案

function countdown(modifiedResult) {
var result = "";

// do something with the result variable
result = modifiedResult;

return result;
}


function something(modifiedResult){
// update private variable "result"
var updatedResult = countdown(modifiedResult);
alert(updatedResult);
}
something("I am updated value");

关于javascript - 用另一个函数修改一个函数的私有(private)变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32180647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com