Skip to content

Instantly share code, notes, and snippets.

@vincesp
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vincesp/23d52bf4f1abb81847ca to your computer and use it in GitHub Desktop.
Save vincesp/23d52bf4f1abb81847ca to your computer and use it in GitHub Desktop.
TypeScript compilation flaw
class AbstractProxy {
private privateBuffer:String = 'abstract';
public usePrivateBuffer = () => {
alert(this.privateBuffer);
}
}
/*
This doesn't compile
*/
class ProxyImplementation extends AbstractProxy {
private privateBuffer:String;
}
/*
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 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