[英]Fixing scope in multiple js nested functions within object
var game = {
num: 0,
playerOne: undefined,
playerTwo: undefined,
setPlayerNum: function() {
swal({
title: "Players",
text: "Enter Number of Players:",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
},
function (inputValue) {
//Figure out code to put here
if (inputValue === "") {
swal.showInputError ("Please a Number");
return false;
}
if (inputValue == 1){
swal("Nice!", "You Entered: " + inputValue, "success");
} else if (inputValue == 2) {
swal("Twice as Nice!", "You Entered: " + inputValue, "success");
}
});
}
};
我有一堆嵌套函數,但我對范圍的了解已離我遠去。 我怎樣才能使function(inputValue)將setPlayerNum:function()的輸入存儲在playerOne:undefined中? 感謝您的所有幫助!
您需要從setPlayerNum
函數返回一些setPlayerNum
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.