После удаления очевидных синтаксических ошибок ваш код, кажется, работает:
let instance = {
'queue': []
};
instance.initQueue = () => {
let _this = instance;
_this['queue'].push = (func,...rest) => {
if (typeof func === 'function') {
// default
Array.prototype.push.apply(_this['queue'], [func, ...rest]);
// process
_this.processQueue();
}
};
_this.processQueue();
};
instance.processQueue = () => {
let _this = instance;
_this['queue'].forEach((func, idx, obj) => {
if (typeof func === 'function') {
func.call(func);
}
obj.splice(idx, 1);
});
};
instance.initQueue();
instance.queue.push(() => console.log(1))
Функции вызываются, как только они помещаются в очередь, из-за:
// process
_this.processQueue();
Вы можете удалить его, чтобы самостоятельно управлять обработкой очереди.