javascript - 如何在 if / else 条件下使用 JavaScript 构造函数类变量?
问题描述
我在控制台中收到一条错误消息,“this.cardPlace”和“this.flipPlace”都未定义。我在 if/else 条件之前运行了一个 console.log,它们都运行正常。我可能缺少一些小东西。(我对编码很陌生,所以请不要给我扔石头,哈哈!)谢谢你的帮助!
class CardSection {
constructor(_cardPlace, _flipPlace, _cat_section, _flipButton, _min, _max) {
this.cardPlace = _cardPlace;
this.flipPlace = _flipPlace;
this.flippy = function() {
if (_flipButton.value == "side-one") {
this.flipPlace++;
_flipButton.value = "side-two";
document.getElementsByClassName("location").innerHTML = "Answer Side";
_cat_section.src = "cards/" + this.cardPlace + "-" + this.flipPlace + ".tiff";
} else if (_flipButton.value == "side-two") {
this.flipPlace--;
_flipButton.value = "side-one";
document.getElementsByClassName("location").innerHTML = "Question Side";
_cat_section.src = "cards/" + this.cardPlace + "-" + this.flipPlace + ".tiff";
}
};
...
var cat_section = document.getElementById("catechism-section-1");
var flipButton = document.getElementById("flip-button1");
var sect1 = new CardSection(1, 1, cat_section, flipButton, 1, 9);
解决方案
推荐阅读
- javascript - Techan.js chart.accessor() 函数说明
- macos - mac上主机的shell脚本不起作用
- python - 在python中使用for循环时重置变量
- javascript - Cloud Firestore 中 get() 和 onSnapshot() 的区别
- nativescript - 如何在保留旧应用程序数据的同时将 Android 原生应用程序升级到基于 NativeScript 的新版本?
- typescript - Costum Pipe 使图像无限循环(闪烁)
- javascript - 在vuejs中使用`v-select`时如何获取`id`值作为选项值和`cname`作为选项标签?
- c# - Excel 互操作只读过滤行
- php - 我无法从控制器访问数据以查看(tpl = 模板)OpenCart
- java - 如何使用 JavaMail 将图像添加到 Freemarker 模板