Javascript 获取方法(对象)外部的变量
我希望在方法之外检索变量,但OOP对我来说是新事物,我有点卡住了Javascript 获取方法(对象)外部的变量,javascript,oop,variables,methods,Javascript,Oop,Variables,Methods,我希望在方法之外检索变量,但OOP对我来说是新事物,我有点卡住了 const Reservation = { play: document.getElementById('Reservation'), reset: document.getElementById('annuler'), launch_functions_sessionStorage: function () { this.onReservation(); this.dis
const Reservation = {
play: document.getElementById('Reservation'),
reset: document.getElementById('annuler'),
launch_functions_sessionStorage: function () {
this.onReservation();
this.displayIfChecked();
this.set_Timer();
},
displayIfChecked: function () {
SOMETHING
},
onReservation: function () {
$('#Reservation, .signature',).click(function () {
console.log();
if (SOMETHING) {
let checked = 1;
} else {
let checked = 0;
}
});
},
set_Timer: function () {
Reservation.play.addEventListener('click', function(){
if('I would like to get 'checked'){}
});
}
};
Reservation.launch_functions_sessionStorage();
我试图保留重要信息以供您理解。
同时为我的英语感到抱歉。。。
非常感谢这就是您要找的吗
const Reservation = {
play: document.getElementById('Reservation'),
reset: document.getElementById('annuler'),
launch_functions_sessionStorage: function () {
this.onReservation();
this.displayIfChecked();
this.set_Timer();
},
displayIfChecked: function () {
SOMETHING
},
onReservation: function () {
$('#Reservation, .signature',).click(function () {
console.log();
if (SOMETHING) {
let checked = 1;
} else {
let checked = 0;
}
});
},
varThatCanBeCheckedInSetTimer : false,
set_Timer: function () {
Reservation.play.addEventListener('click', function(){
if(varThatCanBeCheckedInSetTimer){
//your stuff that will happen only if you set varThatCanBeCheckedInSetTimer to true
}
});
}
};
你会像这样使用它
Reservation.varThatCanBeCheckedInSetTimer = true;
Reservation.set_Timer();
问题出在哪里?如何通过将变量作为参数传递来检查set_timer:function上的变量?我不确定我是否理解这里的问题。我想它可以解决我的问题。同时,我不知道如何在方法之外调用变量。只是^^^类似于
预订。设置时间(参数…
?@LudovicWEBER很乐意帮忙,回答问题并+1被认为是很好的;)