2015-09-25 47 views
0
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"); 
       } 
     }); 
    } 
}; 

我有一堆嵌套的函數,我對範圍的掌握已經離開了我。我怎樣才能讓函數(inputValue)在playerOne中存儲來自setPlayerNum:function()的輸入:undefined,?感謝所有的幫助!固定在對象內的多個js嵌套函數的作用域

回答

0

您需要從您的setPlayerNum函數返回一些東西。