Last active
August 29, 2015 14:08
-
-
Save vincesp/23d52bf4f1abb81847ca to your computer and use it in GitHub Desktop.
TypeScript compilation flaw
This file contains 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 AbstractProxy { | |
private privateBuffer:String = 'abstract'; | |
public usePrivateBuffer = () => { | |
alert(this.privateBuffer); | |
} | |
} | |
/* | |
This doesn't compile | |
*/ | |
class ProxyImplementation extends AbstractProxy { | |
private privateBuffer:String; | |
} |
This file contains 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
/* | |
This is why it doesn't compile | |
*/ | |
var AbstractProxy = (function () { | |
function AbstractProxy() { | |
var _this = this; | |
this.privateBuffer = 'abstract'; //pollutes the "this" namespace | |
this.usePrivateBuffer = function () { | |
alert(_this.privateBuffer); | |
}; | |
} | |
return AbstractProxy; | |
})(); |
This file contains 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
/* | |
This is what the compile should have done | |
*/ | |
function AbstractProxy() { | |
//private area | |
var privateBuffer = 'abstract'; | |
function usePrivateBuffer() { | |
alert(privateBuffer); | |
} | |
//public exports | |
return { | |
usePrivateBuffer: usePrivateBuffer | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment