Promise + gì

promise,es6,async,await,tipjs

Code viết tay: Promise +

const PENDING = 'PENDING';
const RESOLVED = 'RESOLVED';
const REJECTED = 'REJECTED';

class Promise {
	constructor(executor) {
		this.status = PENDING; 
		this.value = undefined; 
		this.reason = undefined; 
		let resolve = (value) => {
			if (this.status === PENDING) {
				this.value = value;
				this.status = RESOLVED;
			}
		};
		let reject = (reason) => {
			if (this.status === PENDING) {
				this.reason = reason;
				this.status = REJECTED;
			}
		};
		
		try {
			executor(resolve, reject);
		} catch(e) {
			console.log('catch::::', e);
			reject(e); 
		}
	}
	then(onfulfilled, onrejected) {
		if (this.status === RESOLVED) {
			onfulfilled(this.value);
		}
		if (this.status === REJECTED) {
			onrejected(this.reason);
		}
	}
}
module.exports = Promise;

Có thể bạn đã miss một số snippets code

Extend Object javascript

Extend Object javascript

How to reverse an Array?

Reversing an array in JS is really simple with the standard array method. Like below

await axios get

await axios get

Rolling loading

Nguyên tắc là theo dõi các sự kiện cuộn trang và phân tích mối quan hệ thuộc tính giữa clientHeight , scrollTop và scrollHeight .

Remove array of objects from another array of objects

Remove array of objects from another array of objects