Skip to content

Instantly share code, notes, and snippets.

View Hydrock's full-sized avatar

Alex Vechkanov Hydrock

View GitHub Profile
async = generator => {
const generator = generatorCreator();
function next(value) {
const nextResult = generator.next(value);
if (nextResult.done) return nextResult.value;
nextResult.value.then(next);
};
next();
class Car {
constructor(maker, model) {
this.maker = maker;
this.model = model;
}
drive() {
console.log("Zoom!");
}
}
class Tesla extends Car {
constructor(model, chargetime) {
super('Tesla', model);
this.chargetime = chargetime;
}
charge() {
console.log("Charging...");
}
}
function Car(maker, model) {
this.maker = maker;
this.model = model;
}
const tesla = new Car('Tesla', '3');
Car.prototype.drive = function() {
console.log("Zoom!");
}
const tesla = new Car('Tesla', '3');
tesla.drive();
function Tesla(model, chargetime) {
Car.call(this, 'Tesla', model);
this.chargetime = chargetime;
}
Tesla.prototype = Object.create(Car.prototype);
Object.defineProperty(Tesla.prototype, ‘constructor’, {value: Tesla, enumerable: false});
Tesla.prototype.charge = function() {
console.log("Charging...");
}
const tesla = new Tesla('3', 20);
tesla.drive();
tesla.charge();
const max = Number.MAX_SAFE_INTEGER;
// → 9007199254740991
max + 1;
// → 9007199254740992
max + 2;
// → 9007199254740992 ❌