Skip to content

Instantly share code, notes, and snippets.

@artalar
Last active September 11, 2019 21:29
Show Gist options
  • Select an option

  • Save artalar/c96e1888931b38a472c39693e1049c4d to your computer and use it in GitHub Desktop.

Select an option

Save artalar/c96e1888931b38a472c39693e1049c4d to your computer and use it in GitHub Desktop.
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