如何使用条件语句检查javascript中构造函数的值?

如何使用条件语句检查javascript中构造函数的值?,javascript,if-statement,constructor,conditional-statements,Javascript,If Statement,Constructor,Conditional Statements,我正在尝试使用Javascript创建一个表单机器人,我想使用条件语句检查在不同函数之外构建的函数的值。我使用以下构造构造此函数: 第一个构造器: 此构造函数创建复选框 class Checkbox { constructor(label, text) { // create the necessary elements this.label = document.createElement(label); this.description = document.createTe

我正在尝试使用Javascript创建一个表单机器人,我想使用条件语句检查在不同函数之外构建的函数的值。我使用以下构造构造此函数:

第一个构造器: 此构造函数创建复选框

class Checkbox {
  constructor(label, text) {
  // create the necessary elements
  this.label = document.createElement(label);
  this.description = document.createTextNode(text);
  this.checkbox = document.createElement("input");

  this.checkbox.type = "checkbox"; // make the element a checkbox
  this.checkbox.name = "slct[]"; // give it a name we can check on the server side
  this.checkbox.value = text; // make its value "pair"

  this.label.appendChild(this.checkbox); // add the box to the element
  this.label.appendChild(this.description); // add the description to the element

  // add the label element to your div
  document.getElementById("myform").appendChild(this.label);
}
};
第二构造器 这将创建在表单中填充的文本

然后,我创建了一个复选框,希望我的表单自动运行

var options = {};
function feelingCheckboxs() {
  option.happy = new FeelingCheckbox(feeling, "happiness");
  option.Sad = new feelingCheckbox(feeling, "Sad");
  option.angry = feelingCheckbox(feeling, "angry");
}
这是我创建的机器人 问题:
如何进行条件语句检查以确保复选框已选中,以便它可以打印语句。未定义“

feelingCheckbox
”。如果它是
Checkbox
的子类,则只需获取实例的
Checkbox
属性的
checked
值即可。@HereticMonkey ok我更新了调用该子类的方式。但事实并非如此work@HereticMonkey你能看一下更新的代码吗?你在if语句中使用赋值运算符而不是相等运算符,例如,你应该写if(option.happy.checked)它实际上是option.happy.checked=true吗@伍迪
bot() {
 if (counter == 2) {
       if (option.happy.checked = true 
            && option.sad.checked = true 
            && option.angry.checked = true ) {
      alert(
        "I am " + feelingCheckboxs(happy) + "and" + feelingCheckboxs(sad) + "and" + feelingCheckboxs(angry) + "!"
      );