Can I change the context of javascript "this"?

Hcabnettek picture Hcabnettek · Jun 26, 2009 · Viewed 26.8k times · Source
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?

Answer

James picture James · Jun 26, 2009

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.