Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript:事件对象引用_Javascript_Scope - Fatal编程技术网

Javascript:事件对象引用

Javascript:事件对象引用,javascript,scope,Javascript,Scope,我目前正忙于创建一个“纯js页面”(没有HTML内容,没有CSS,只是JSON提供了一个“构造函数”),偶然发现了一个我认为与函数范围有关的问题,我无法解决 “严格使用” var x=类{ 构造函数(args){ console.log('class')) this.a=args[0] this.b=args[1] this.c=args[2] this.d=this.d.bind(this) this.e=this.e.bind(this) 这是 } } x、 prototype.d=函数

我目前正忙于创建一个“纯js页面”(没有HTML内容,没有CSS,只是JSON提供了一个“构造函数”),偶然发现了一个我认为与函数范围有关的问题,我无法解决


“严格使用”
var x=类{
构造函数(args){
console.log('class'))
this.a=args[0]
this.b=args[1]
this.c=args[2]
this.d=this.d.bind(this)
this.e=this.e.bind(this)
这是
}
}
x、 prototype.d=函数(){
console.log('listener')
document.getElementById('h').addEventListener('mouseover',this.e,false)
}
x、 prototype.e=函数(){
console.log('handler')
这个a(这个b)
}
var f=函数(args){
console.log('调用:'+args)
console.log(event.target)
}
var g=函数(args){
新x(args)
}
洛勒姆。。。

似乎您没有传递事件参数
this.a(e,this.b)}
。请参阅更新的代码段:


“严格使用”
var x=类{
构造函数(args){
console.log('class'))
this.a=args[0]
this.b=args[1]
this.c=args[2]
this.d=this.d.bind(this)
this.e=this.e.bind(this)
这是
}
}
x、 prototype.d=函数(){
console.log('listener')
document.getElementById('h').addEventListener('mouseover',this.e,false)
}
x、 prototype.e=函数(e){
console.log('handler')
setTimeout(()=>{this.a(e,this.b)},this.c)
}
var f=函数(事件,参数){
console.log('调用:'+args)
console.log(event.target)
}
var g=函数(args){
新x(args)
}
洛勒姆。。。

函数
f
不知道
事件是什么。您的第一个代码段在Chrome中工作,但在FireFox中不工作。不要依赖浏览器的魔力。将
事件
指定为回调函数的参数是标准做法。