[Solved] How to modify “this” in javascript


You can use .call(context[, params])and .apply(context[, arguments]) to do this. For example:

function move(x, y) {
    this.style.left = x + "px";
    this.style.top = y + "px";
};

// now this in move refers to the div element
move.call($('div')[0], 100, 200);

But you can’t just overwrite this.

solved How to modify “this” in javascript