我可以更改javascript“this”的上下文吗?
16lz
2021-01-22
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);
};
is this possible? Thanks, ~ck in San Diego
这可能吗?谢谢,〜在圣地亚哥
3 个解决方案
#1
No, it's not possible.
不,这是不可能的。
You can call a method with a specified value for this (using method.apply()
/method.call()
) but you cannot re-assign the keyword, this
.
您可以为此调用具有指定值的方法(使用method.apply()/ method.call()),但不能重新分配关键字。
更多相关文章
- 为什么分配给True / False不能像我期望的那样工作?
- numpy无法将值分配给列的一部分
- 深入理解Java虚拟机读书笔记---垃圾回收与内存分配
- java基础---JVM---调优,垃圾收集器,内存分配策略