我可以更改javascript“this”的上下文吗? [英] Can I change the context of javascript "this"?
本文介绍了我可以更改javascript“this”的上下文吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var UI$Contract$ddlForm_change = function() {
//'this' is currently the drop down that fires the event
// My question is can I change the context so "this" represents another object?
this = SomeObject;
// then call methods on the new "this"
this.someMethod(someParam);
};
这可能吗?
推荐答案
不,这是不可能的。
您可以为 this 调用一个具有指定值的方法(使用<强> method.apply()
强> / <强> method.call()
强> )但您无法重新分配关键字 此
。
You can call a method with a specified value for this (using method.apply()
/method.call()
) but you cannot re-assign the keyword, this
.
这篇关于我可以更改javascript“this”的上下文吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文