aspromise

0.1.0 • Public • Published

asPromise

Description

asPromise is a micro promise implementation which behaves well with any JavaScript object. It works in the browser and server (node.js). The code follows a functional mixins pattern described by Angus Croll a-fresh-look-at-javascript-mixins.

Usage

In browser include single JavaScript file:

<script src="aspromise.js"></script>

On server install asPromise via npm first:

npm install aspromise

and then include it in your project with:

var asPromise = require('asPromise');

Example Usage

Define the constructor which will make use of asPromise:

function Model() {}

Add (mixin) asPromise functionality to Model with:

asPromise.call(Model.prototype);

model has now access to then, resolve and reject functions

Add some async functions to Model:

Model.prototype.doAsyncWork = function () {
  var self = this;
  setTimeout(function () {
    self.resolve();
  }, 1000);
  return this;
}

Create a new object and use it:

var model = new Model();
model.doAsyncWork().then(function () {
  // work done
});

License:

(The MIT License)

Copyright (c) 2012 Michal Kuklis

Readme

Keywords

none

Package Sidebar

Install

npm i aspromise

Weekly Downloads

10

Version

0.1.0

License

none

Last publish

Collaborators

  • mkuklis