Skip to content

Instantly share code, notes, and snippets.

@softwaredoug
Last active February 14, 2024 01:41
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save softwaredoug/9044640 to your computer and use it in GitHub Desktop.
Save softwaredoug/9044640 to your computer and use it in GitHub Desktop.
var Promise = function(wrappedFn, wrappedThis) {
this.then = function(wrappedFn, wrappedThis) {
this.next = new Promise(wrappedFn, wrappedThis);
return this.next;
};
this.run = function() {
wrappedFn.promise = this;
wrappedFn.apply(wrappedThis);
};
this.complete = function() {
if (this.next) {
this.next.run();
}
};
};
Promise.create = function(func) {
if (func.hasOwnProperty('promise')) {
return func.promise;
} else {
return new Promise();
}
};
@dopatraman
Copy link

Doesnt work. Can you please provide a full example?

foo = new Promise(function() {return [1,2,3,4];});

foo()

TypeError: object is not a function

Also doesnt work:

foo.then(function(i) {return i}).complete()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment