我希望在方法之外检索变量,但OOP对我来说是新的,我有点卡住...
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();
我试图保留重要信息以便您理解。 同时抱歉我的英语...... 非常感谢你
答案 0 :(得分:2)
这是你在找什么?
for
你会像
一样使用它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
}
});
}
};