我可以问一下javascript中的'this'是什么意思,'this'上的任何资源,以及表单中的this.submit是什么意思?
答案 0 :(得分:3)
答案 1 :(得分:2)
答案 2 :(得分:1)
this
指的是当前对象。所以,如果我有类似的东西:
var someVar = {
some: 'thing',
another: function(){
return "thing";
},
more: function(){
this.some + this.another();
}
}
然后这些陈述中的this
引用了someVar
,因此您正在调用another()
成员的someVar
函数...
答案 3 :(得分:0)
this
是对象的 self 引用。
在对象中使用,this
指的是该对象本身。
在外部使用(不在对象内)this
是指全局对象。
因此
function Func(z) { this.x = z; }
并正在运行
Func(7);
将全局变量 x 设置为7。
在做的时候
var o = new Func(3);
var p = new Func(4);
将创建两个对象 o 和 p ,并将Func实例化 x 的属性设置为 o 为3, p 为4。
精心设计的解释见this site。
答案 4 :(得分:0)
下面的PDF中的文字深入解释了“这个” - 以及它如何变化。
https://github.com/spencertipping/js-in-ten-minutes/blob/master/js-in-ten-minutes.pdf
(抱歉,无法在网上直接访问,您必须下载内容)