Skip to content

Instantly share code, notes, and snippets.

View bitfishxyz's full-sized avatar
🐥
🐔🐔🥚🥚

medium003 bitfishxyz

🐥
🐔🐔🥚🥚
View GitHub Profile
class MyPromise{
constructor(executor) {
this.status = "pending";
this.value = undefined;
// This array is used to store all the onResolve functions in the chain call
this.resolveArr = [];
// // This array is used to store all the onReject functions in the chain call
this.rejectArr = [];
class MyPromise{
constructor(executor) {
this.status = "pending";
this.value = undefined;
// This array is used to store all the onResolve functions in the chain call
this.resolveArr = [];
// // This array is used to store all the onReject functions in the chain call
this.rejectArr = [];
class MyPromise{
constructor(executor) {
// The initial state of the Promise object should be pending
this.status = "pending";
// Store the value after success or reason after fail
this.value = undefined;
// Define a resolve function
let resolve = result => {
function asyncToGenerator(generatorFunc) {
// A new function is returned
return function() {
// First call the generator function to generate the iterator
// Corresponding to: var gen = testG()
const gen = generatorFunc.apply(this, arguments)
// return a promise object
return new Promise((resolve, reject) => {
function asyncToGenerator(generatorFunc) {
return function() {
const gen = generatorFunc.apply(this, arguments)
return new Promise((resolve, reject) => {
function step(key, arg) {
let generatorResult
try {
generatorResult = gen[key](arg)
} catch (error) {
return reject(error)
function* testG() {
// await is translated as yield
const data = yield getData()
console.log('data: ', data);
const data2 = yield getData()
console.log('data2: ', data2);
return 'success'
}
var gen = testG()
var dataPromise = gen.next()
function checkAuth(data) {
if (data.role !== 'registered') {
console.log('The user is not a registered user');
return false;
}
if (data.grade < 1) {
console.log("The user's level is less than 1");
return false;
}
if (data.job !== 'FE') {
const jobList = ['FE', 'BE'];
var strategies = {
checkRole: function(value) {
if (value === 'registered') {
return true;
}
return false;
},
checkGrade: function(value) {
if (value >= 1) {
var compose2 = function() {
var validator = new Validator();
const data2 = {
role: 'register',
job: 'FE'
};
validator.add(data2.role, 'checkRole');
validator.add(data2.job, 'checkJob');
const result = validator.check();
return result;
import React from 'react';
import yellowHOC from './yellowHOC';
class TargetComponent extends Reac.Compoment {
render() {
return <div>hello world</div>;
}
}
export default yellowHOC(TargetComponent);