zoukankan      html  css  js  c++  java
  • 直观的链式回调 MyPromise

    function MyPromise(fun) {
    	let self = this;
    	self.then = function (resolve, error) {
    		resolve&&resolve(self.value);
    		error&&error(self.errValue);
    		return this;
    	}
    
    	function resolve (value) {
    		self.value = value;
    	}
    
    	function error (value) {
    		self.errValue = value;
    	}
    
    	fun(resolve, error);
    }
    
    function test () {
    	return new MyPromise(function(resolve,error){
    		resolve("我是个正确值");
    		error('我是个错误值');
    	});
    }
    
    test().then(function(result){
    	console.info('result = ', result)
    }).then(function(result){
    	console.info('result = ', result)
    });
    

  • 相关阅读:
    Spring aop 实现异常拦截
    drf 视图家族
    算法与数据结构
    接口
    Kubernetes
    drf
    drf 序列化
    drf 内部模块
    drf 接口
    vue
  • 原文地址:https://www.cnblogs.com/SATinnovation/p/10131539.html
Copyright © 2011-2022 走看看