This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async = generator => { | |
| const generator = generatorCreator(); | |
| function next(value) { | |
| const nextResult = generator.next(value); | |
| if (nextResult.done) return nextResult.value; | |
| nextResult.value.then(next); | |
| }; | |
| next(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Car { | |
| constructor(maker, model) { | |
| this.maker = maker; | |
| this.model = model; | |
| } | |
| drive() { | |
| console.log("Zoom!"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Tesla extends Car { | |
| constructor(model, chargetime) { | |
| super('Tesla', model); | |
| this.chargetime = chargetime; | |
| } | |
| charge() { | |
| console.log("Charging..."); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Car(maker, model) { | |
| this.maker = maker; | |
| this.model = model; | |
| } | |
| const tesla = new Car('Tesla', '3'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Car.prototype.drive = function() { | |
| console.log("Zoom!"); | |
| } | |
| const tesla = new Car('Tesla', '3'); | |
| tesla.drive(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Tesla(model, chargetime) { | |
| Car.call(this, 'Tesla', model); | |
| this.chargetime = chargetime; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const max = Number.MAX_SAFE_INTEGER; | |
| // → 9007199254740991 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| max + 1; | |
| // → 9007199254740992 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| max + 2; | |
| // → 9007199254740992 ❌ |