我想知道是否可以在 javascript 中替换函数的范围对象。我有一个非常复杂的事件处理程序,我想将它从另一个函数中提取出来并将其存储在其他地方。然后我希望能够检索处理程序,替换其范围,并将其作为处理程序传递。
示例代码:
function A(event){
}
function B(){
// many variables initialized here that I want to be available from within A...
// the line where I would like to bind these variables to A
$form.on("submit", A);
}