Last active
September 11, 2019 21:29
-
-
Save artalar/c96e1888931b38a472c39693e1049c4d to your computer and use it in GitHub Desktop.
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 Test { | |
| constructor(){/*...*/} | |
| set(data){ | |
| this.#data = data | |
| } | |
| get(){ | |
| return this.#data | |
| } | |
| } | |
| // transpile to... | |
| function testConstructor(){} | |
| class Test { | |
| constructor(...a){ | |
| let _data | |
| const instance = { | |
| set(data){ | |
| _data = data | |
| }, | |
| get(){ | |
| return _data | |
| } | |
| } | |
| instance.__proto__ = Test.prototype | |
| testConstructor.apply(instance, a) | |
| return instance | |
| } | |
| } | |
| var test = new Test | |
| console.log(1, test instanceof Test) | |
| console.log(2, test.data) | |
| console.log(3, test.get()) | |
| test.set('data') | |
| console.log(4, test.get()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment