Created
April 4, 2022 20:32
-
-
Save pablo-rufat/29bf49273e3ec8c2f853d6172c39f280 to your computer and use it in GitHub Desktop.
Demonstração da diferença entre prototype functions e arrow functions dentro de uma classe typescript ao ser transpilada para javascript.
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
// Classe typescript | |
class TestClass { | |
private _atributo; | |
constructor(atributo: string) { | |
this._atributo = atributo; | |
} | |
get atributo(): string { | |
return this._atributo; | |
} | |
testArrow = () => { | |
console.log('do something'); | |
} | |
normalMethod() { | |
console.log('this is prototype'); | |
} | |
} | |
export default TestClass; | |
// Classe transpilada para javascript | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
class TestClass { | |
constructor(atributo) { | |
this.testArrow = () => { | |
console.log('do something'); | |
}; | |
this._atributo = atributo; | |
} | |
get atributo() { | |
return this._atributo; | |
} | |
normalMethod() { | |
console.log('this is prototype'); | |
} | |
} | |
exports.default = TestClass; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment