Set “this” variable easily?
问题 I have a pretty good understanding of Javascript, except that I can\'t figure out a nice way to set the \"this\" variable. Consider: var myFunction = function(){ alert(this.foo_variable); } var someObj = document.body; //using body as example object someObj.foo_variable = \"hi\"; //set foo_variable so it alerts var old_fn = someObj.fn; //store old value someObj.fn = myFunction; //bind to someObj so \"this\" keyword works someObj.fn(); someObj.fn = old_fn; //restore old value Is there a way to