Javascript 如何使用布尔标志跳过特定事件?
我正在制作一个函数,它将两个事件组合在一个Javascript 如何使用布尔标志跳过特定事件?,javascript,events,boolean,flags,touchstart,Javascript,Events,Boolean,Flags,Touchstart,我正在制作一个函数,它将两个事件组合在一个方法上,以便更好地控制、编辑,并且更容易,如下所示: 类事件管理器{ 建造商(el){ 这.$el=$el; this.main开关=假; this.subSwitch=false; this.condition=(!this.main开关&&!this.subSwitch);//则为false this.condition2=(!this.mainSwitch&&this.subSwitch);//则为false-true } 开始(e){ 如果(本
方法上,以便更好地控制、编辑,并且更容易,如下所示:
类事件管理器{
建造商(el){
这.$el=$el;
this.main开关=假;
this.subSwitch=false;
this.condition=(!this.main开关&&!this.subSwitch);//则为false
this.condition2=(!this.mainSwitch&&this.subSwitch);//则为false-true
}
开始(e){
如果(本条件){
console.log(e.type);
this.main开关=真;
return false;//结束函数的return关键字
}else if(此条件2){
this.main开关=假;
this.subSwitch=false;//返回默认语句。
返回false;
}
返回false;
}
动议(e){
if(this.mainSwitch==true&&this.subSwitch==false){
console.log(e.type);
}
}
完(戊){
if(this.mainSwitch==true&&this.subSwitch==false){
console.log(e.type);
this.main开关=假;
this.subSwitch=true;
}
}
应用(){
此.$el.on('touchstart mousedown',(e)=>{
这是第一次启动(e);
})
$('html')。在({
['touchmove mousemove']:(e)=>this.move(e),
['touchend mouseup']:(e)=>this.end(e)
})
}
}
var thatEvent=neweventmanager($('#link');
thatEvent.apply()代码>
a{
宽度:100%;
高度:100px;
边界半径:10px;
背景颜色:棕色;
字体系列:Helvetica;
显示器:flex;
柔性流:行;
证明内容:中心;
对齐项目:居中;
}
此.condition的值也此.condition 2
不会在您的事件中更改
您只需更改main开关
和子开关
变量。这并不意味着你改变了这两个条件,也就改变了这个条件变量。因为该值仅从初始化/构造函数设置
最好将this.condition
对象更改为函数,使其更具动态性。因此,它将始终依赖于您的主开关和子开关this的值。条件也this。条件2
不会在您的事件中更改。。您只需更改main开关
和子开关
变量。这并不意味着你改变了这两个条件,也就改变了这个条件变量。因为此值仅从初始化/构造函数设置,所以最好将this.condition
对象更改为函数,使其更具动态性。因此,它将始终依赖于您的主开关和subswitch@JohnChristianDeChavez:o我认为当我在函数内部使用它时,constructor
的值会改变它。听了你的建议,它就如我所愿。非常感谢,构造函数只在初始化类后运行。