Answer the question
In order to leave comments, you need to log in
Is it possible to somehow override, inherit this for an anonymous function?
Let's say we have a code
var test = function(foo){
/* тут действия */
// формируем собственный this
// функция foo должна уметь работать с нашим новым this
foo();
};
test(function(){
this.MyMethod();
});
Answer the question
In order to leave comments, you need to log in
Might try like this:
var test = function(foo){
/* тут действия */
var anythis=...; // формируем собственный this
// функция foo должна уметь работать с нашим новым this
foo.call(anythis); //Или apply, надо под ситуацию подстраиваться.
//Или так:
func=foo.bind(anythis);
func();
};
test(function(){
this.MyMethod();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question