Just starting to use TypeScript and I can't find explanation for this issue...
Lets say I have function
function test() {
function localAccessMethod() {
console.log('I am only accessable from inside the function :)');
}
this.exposedMethod = function () {
console.log('I can access local method :P');
localAccessMethod();
}
}
And I want to convert this to typescript class... So far I did it up to here:
class test {
constructor: {}
exposedMethod() {
console.log('I can access local method :P');
localAccessMethod();
}
}
How can I define that local function in the typescript class, so it wouldn't be exposed as prototype or .this... ?
Or better question, how should I convert the source code to fit TypeScript standard. I want to have function which is available for all class methods only, but is not exposed...
You can to use private static
keywords:
class Test
{
private static localAccessMethod()
{
console.log('I am only accessable from inside the function :)');
}
exposedMethod()
{
console.log('I can access local method :P');
Test.localAccessMethod();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With