Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dtipson/5ff99dadeba9ec5130ec to your computer and use it in GitHub Desktop.

Select an option

Save dtipson/5ff99dadeba9ec5130ec to your computer and use it in GitHub Desktop.
function done_wrapper(fn){
return function(value){
fn(value);
return value;
};
}
function badlog(x){
console.log(x);
return 'return a complete nonsense string!';
}
var g = Promise.resolve(5)
.then( done_wrapper( badlog ) )// protected usage
.then( function(value){
return value + 1;
})
.then( badlog );// unprotected usage
// logs: 5
// adds 1
// logs 6
// but g = Promise {
// [[PromiseStatus]]: "resolved",
// [[PromiseValue]]: "return a complete nonsense string!"
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment