gpt4 book ai didi

javascript - JS - 如何正确放置局部变量

转载 作者:行者123 更新时间:2023-11-28 20:04:11 25 4
gpt4 key购买 nike

我有一个 JS 模块,我想为局部变量设置一个值。我想我可以使用“this”来使用相同的名称:

JS

(function() {
var amount = 0;
var setAmount = function(amount) {
this.amount = amount;
}
........
})();

最佳答案

amount 在函数范围内,因此不需要 this 关键字。

(function(){

var amount = 0;

var setAmount = function( newAmount ){
amount = newAmount;
}
})();

关于javascript - JS - 如何正确放置局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21126083/

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