javascript - 我可以更改 javascript "this"的上下文吗?

标签 javascript this dom-events

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()),但您无法重新分配关键字 this

关于javascript - 我可以更改 javascript "this"的上下文吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1051237/

相关文章:

javascript - react-sound-强制React组件更新并定位?

c++ - 是否可以在 C++ 中使用 "this"在成员函数中创建本地对象?

java - LoaderManager 不接受 'this'

c++ - 这个指针的使用

javascript - 可以在拖动开始后异步设置 event.dataTransfer 吗?

javascript - Safari 2.0 中修饰键的键盘事件

javascript - 根据父宽度定位绝对顶部属性

javascript - Modernizr 和 Video.h264

javascript - 如何使用纯 Javascript 将 onclick 函数添加到动态创建的 div

javascript - 动态 URL 更改,无需重新加载页面