我能';不要使用pop()?javascript

我能';不要使用pop()?javascript,javascript,constructor,Javascript,Constructor,我已经设置了一些构造函数类,我正在尝试弹出这个元素。因为某种原因我不能。我可以叫它,但我打不开,也不知道为什么。我发布了完整的代码(这是一个uno游戏)。我认为这可能与播放器在不同的构造函数中被调用有关,但我使用了回调,所以我想我应该能够像处理所有函数一样修改它 作为替代方案,我可能会在播放器内部创建一个允许pop的函数,但我想了解一些细节 代码的一半是一行未编码的代码,我遇到了问题 function Card(color, value){ this.color = color this

我已经设置了一些构造函数类,我正在尝试弹出这个元素。因为某种原因我不能。我可以叫它,但我打不开,也不知道为什么。我发布了完整的代码(这是一个uno游戏)。我认为这可能与播放器在不同的构造函数中被调用有关,但我使用了回调,所以我想我应该能够像处理所有函数一样修改它

作为替代方案,我可能会在播放器内部创建一个允许pop的函数,但我想了解一些细节

代码的一半是一行未编码的代码,我遇到了问题

function Card(color, value){
  this.color = color
  this.value = value
  var values = {
    10: "Skip",  // 2 per color
    11: "Draw 2",  //2 per color
    12: "Reverse", //2 per color
    13: "Wild",  // 4 wilds
    14: "Wild Draw Four" //4 of these
  }
  var color = ["Green", "Blue", "Yellow", "Red"]
  if (values[this.value]){
    this.name = `${values[this.value]} of ${color[this.color]}`
  }
  else{
    this.name = `${this.value} of ${color[this.color]}`
  }
}
function Deck(){
  this.deck = []
  this.pile = []
  for (var color = 0; color < 4; color ++){
    for (var value = 0; value <= 14; value++){
      this.deck.push(new Card(color, value))
    }
  }
  for (var color = 0; color < 4; color ++){
    for (var value = 1; value <=12; value++){
      this.deck.push(new Card(color, value))
    }
  }
  this.shuffle = function(){
    for (var i = 0; i<this.deck.length; i++){
      var j = Math.floor(Math.random()*this.deck.length)
      var temp = this.deck[j]
      this.deck[j] = this.deck[i]
      this.deck[i] = temp
    }
  }
  }

function Player(hand, name, callname){
  this.hand = hand
  this.name = name
  this.callname = callname
}
function functioning_turns(players, my_deck){
  console.log(players);
  for(var i = 0; i < players.length; i++){
    current = players[i]
    console.log(current);
    name_curr = players[i].name
    top_pile = my_deck.pile[0].name
    console.log('It\'s '+name_curr+ ' turn.')
    for (var i = 0; i < current.hand.length;i++){
      console.log(current.hand[i].name);
    }
    function play_card(){
      var ploy = prompt("Please enter card position to play: 0-N (n is number of cards)\n\nTop of pile: "+ top_pile, "Starts at zero");
      console.log(current.hand[ploy]);
功能卡(颜色、值){
这个颜色
this.value=value
var值={
10:“跳过”//2每种颜色
11:“绘制2”//2每种颜色
12:“反向”,每种颜色2个
13:“野性”//4野性
14:“任意抽取四个”//4个
}
var color=[“绿色”、“蓝色”、“黄色”、“红色”]
if(值[this.value]){
this.name=${color[this.color]}的${values[this.value]}`
}
否则{
this.name=`${color[this.color]}的${this.value}`
}
}
功能组(){
this.deck=[]
this.pile=[]
用于(var color=0;color<4;color++){

对于(var value=0;value如果我很好地理解您的问题,那么您正在尝试对字符串调用
Array.prototype.pop()

这项工作:

var-arr=['a','b','c'];
arr.pop();

console.log(arr);
什么是“不能弹出”意思?有错误吗?为什么不解释一下你想做什么和实际发生了什么。什么是“不能”?Current不是声明的。它是一个隐式全局。在文件的最顶端添加
“使用严格”
。试试console.log
Current.hand[ploy]
弹出()如果数组为空,则
将返回未定义的
。使用
当前.hand.splice(ploy,1)
删除数组中位置ploy处的1个对象
当前.hand
      console.log(current.hand[ploy].pop())};
    //   if(this.hand[play] == 'skip' || 'Skip'){
    //
    // }
    play_card()
    }
  }
function start_game(){
  var playernames = []
  var num_of_players = prompt("Please enter number of players", "4")
  var my_deck = new Deck()
  my_deck.shuffle()
  var x = 1
  while (x <= num_of_players){
    var player_names = prompt("Please enter player name", "shawn");
    curr_hand = []
    my_deck.deal = function(){
      return curr_hand.push(my_deck.deck.pop())}
    for(var i = 0; i<7; i++){
      my_deck.deal();
      }
    newplayer = player_names+x
    newplayer = new Player(curr_hand, player_names, newplayer);
    playernames.push(newplayer);
    x++;
    }
  my_deck.pile.push(my_deck.deck.pop())
  console.log(my_deck.deck);
  var game = new functioning_turns(playernames, my_deck)
}
start_game()