Skip to content

Commit

Permalink
Shimmed ES5 Object.create for progressive enhancement.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Nov 17, 2010
2 parents c7bdbc3 + 479161c commit 140adcc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

0.1.7
- shimmed ES5 Object.create in addition to Object.freeze
for compatibility on non-ES5 engines (gozala)

0.1.6
- Q.isResolved added
- promise.valueOf() now returns the value of resolved
Expand Down
12 changes: 9 additions & 3 deletions lib/q.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ if (typeof console !== "undefined") {
print = function () {}
}

// useful in a couple places
// useful for an identity stub and default resolvers
function identity (x) {return x}

// ES5 shims
var freeze = Object.freeze || identity;
var create = Object.create || function create(prototype) {
var Type = function () {};
Type.prototype = prototype;
object = new Type();
}

/**
* Performs a task in a future turn of the event loop.
Expand Down Expand Up @@ -104,7 +110,7 @@ function defer() {
// resolved values and other promises gracefully.
var pending = [], value;

var promise = Object.create(Promise.prototype);
var promise = create(Promise.prototype);

promise.emit = function () {
var args = Array.prototype.slice.call(arguments);
Expand Down Expand Up @@ -162,7 +168,7 @@ function Promise(descriptor, fallback, valueOf) {
};
}

var promise = Object.create(Promise.prototype);
var promise = create(Promise.prototype);

promise.emit = function (op, resolved /* ...args */) {
resolved = resolved || identity;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "q",
"description": "defer/when-style promises (CommonJS/Promises/B)",
"version": "0.1.6",
"version": "0.1.7",
"homepage": "http://github.com/kriskowal/q/",
"author": "Kris Kowal <[email protected]> (http://github.com/kriskowal/)",
"contributors": [
Expand Down

0 comments on commit 140adcc

Please sign in to comment.