我正在尝试命名我的类,但出现以下错误。如何将类添加到对象字面量?
Helpers = window.Helpers || {};
Helpers.Bootstrap = Helpers.Bootstrap || {};
Helpers.Bootstrap.Spinner = {
class loader {
constructor(element = '.spinner-border') {
this.element = $(this)
}
show() {
this.element.css("display", "block");
}
hide() {
this.element.css("display", "none");
}
},
class button {
constructor(element = '.btn_spinner') {
this.element = $(this);
this.html = $(this).html();
}
show() {
$(this).prop("disabled", true);
$(this).html(
`<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>Loading...`
);
}
hide() {
this.element.prop("disabled", false);
this.element.html(this.html);
}
}
}
document.addEventListener("DOMContentLoaded", function(event) {
const SpinnerBtn = new Helpers.Bootstrap.spinner.button();
});
我尝试在下面简化问题。
Helpers = window.Helpers || {};
Helpers.Bootstrap = Helpers.Bootstrap || {};
Helpers.Bootstrap.Spinner = {
Loader: class Loader {
}
},
Button : class Button {
}
}
document.addEventListener("DOMContentLoaded", function(event) {
const SpinnerBtn = new Helpers.Bootstrap.Spinner.Button();
});
错误:
语法错误:意外的标识符“加载程序”。应在属性名称“class”后面有一个“:”。
30秒到达战场
相关分类