class Foo {
constructor() {
this.queue = [];
}
pFunc(i,pGen) {
return pGen();
}
bar() {
const _bar = () => {
return new Promise( (resolve,reject) => {
setTimeout( () => {
console.log('bar');
resolve();
}, 1000);
})
}
this.queue.push(_bar);
return this;
}
baz() {
const _baz = () => {
return new Promise( (resolve,reject) => {
setTimeout( () => {
console.log('baz');
resolve();
}, 1000);
})
}
this.queue.push(_baz);
return this;
}
then(func) {
return Promise.reduce(this.queue, this.pFunc, 0).then(func);
}
}
const foo = new Foo();
foo.bar().baz().then(() => console.log('done'));
anybodyName() {
return new Promise(resolve => {
setTimeout(() => {
this.anybodyProperty = 1;
resolve(this);
}, 1000);
});
}
var some = new SomeClass();
some.anybodyName().then(self => self.otherMethod());
some.anybodyName().then(() => some.otherMethod())
.then(() => some.thirdMethod());
А зачем вам вообще понадобилось тянуть JQuery?