Answer the question
In order to leave comments, you need to log in
How to recursively call a function given in a variable?
Simplified function code:
var func = function(items, errors) {
if (items.length) {
$.post(
'/items/add/',
{id: items.pop()},
function (response) {
if (typeof response.error != 'undefined') {
errors.push(response.error);
} else {
// как осуществить вызов функции из переменной func (рекурсивный вызов)?
...(items, errors);
}
},
'json'
);
} elseif (errors.length) {
alert(errors.join(' '));
}
};
func(new_items, []);
var func = function(fself, items, errors) {
...
fself(fself, items, errors);
...
};
func(func, new_items, []);
function func(items, errors) {
...
func(items, errors);
...
}
func(new_items, []);
Answer the question
In order to leave comments, you need to log in
Do you mean so?
var func = function funcSelf(items, errors) {
// тут всякий код
funcSelf(); // вызываем, используя имя funcSelf, которое доступно только внутри функции
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question