JS Prototype没有运行其全部功能

时间:2016-06-22 21:56:05

标签: javascript constructor prototype

这是我的代码,我正在尝试为游戏设置一个组合锁定,当用户输入正确的答案时,该游戏将解锁。但是,当用户输入内容时,它将始终返回“门已解锁”。我在这里错过了什么或做错了什么?

function comboLock(){
  this.comboLock = ["666"];
  this.falseInput = /[^1-5, 7-9]/g;
}
comboLock.prototype.unlock = function(){
  if (this.comboLock != this.falseInput){
    return alert("the door is unlocked");
  }
  else if (this.comboLock === this.falseInput){
    return alert("that is not the correct combonation");
  }
}

$(document).ready(function(){
  $("#button-unlock").click(function(event) {
    event.preventDefault();
    if (this.comboLock = "666"){
      return alert("the door is unlocked");
    }
    else if (this.comboLock != "666"){
      return alert("that is not the correct combonation");
    }
  })
})

0 个答案:

没有答案