anima-promise

v3.0.1
移动端的 Promise/A+ 实现
promise

anima-promise


移动端的 Promise/A+ 实现,符合标准Promise的规范

Install

$ tnpm  install anima-promise --save

Normal Usage

下面是ES6代码的例子,也可以采用ES5进行开发


import Promise from 'anima-promise';

function foo() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(1);
    });
  });;
}

foo().then(value => {
  console.log(value); // 1
});

// Deferred

const Deferred = function() {
  this.promise = new Promise((resolve, reject) => {
    this.resolve = resolve;
    this.reject = reject;
  });

  this.then = this.promise.then.bind(this.promise);
  this.catch = this.promise.catch.bind(this.promise);
};


function far() {
  const d = new Deferred();
  setTimeout(() => {
    d.resolve('a')
  }, 10);

  return d.promsie;
}

foo().then(value => {
  console.log(value); // a
});

更多API请参考MDN的Promise介绍

Metadata

Downloads

Maintainers