Skip to content

Instantly share code, notes, and snippets.

@yclian
Last active August 29, 2015 14:25
Show Gist options
  • Save yclian/f097595880c9d68e0b54 to your computer and use it in GitHub Desktop.
Save yclian/f097595880c9d68e0b54 to your computer and use it in GitHub Desktop.
// Run: `node --harmony car.js`
"use strict";
var Car = function(brand) {
this.brand = brand;
this.vroom = function() {
console.log(this.brand + " is slow");
return new Promise(function(f) {
console.log(this.brand + " is slow"); f("vroom");
}.bind(this));
};
this.vrooom = () => {
console.log(this.brand + " is fast");
return new Promise((f) => {
console.log(this.brand + " is fast"); f("vrooom");
});
};
};
var c = new Car("Mazda");
c.vroom().then(function(r) { console.log('Promised: ' + r); }, function(e) { console.log('Broken: ' + e); });
c.vrooom().then(function(r) { console.log('Promised: ' + r); }, function(e) { console.log('Broken: ' + e); });
@yclian
Copy link
Author

yclian commented Jul 27, 2015

Expected:

Mazda is slow
Mazda is slow
Mazda is fast
Promised: vroom
Broken: TypeError: Cannot read property 'brand' of undefined

Desired:

Mazda is slow
Mazda is slow
Mazda is fast
Mazda is fast
Promised: vroom
Promised: vrooom

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