2

I'm wondering what's the way to access a private static field within the same class assuming that class isn't exported.

module Test {
    class Template {
        private static ext = '.hbs';
        private static basePath = 'WebContent/templates/';
        private static templatesFolder = 'templates';
        private static partialsFolder = 'partials';
        private static paymentMethodsFolder = 'paymentMethods';

        public static template(templateName, data): string{
            return Handlebars.templates[Test.Template.basePath + this.templatesFolder + '/' + templateName + this.ext];
        }
    }
}

I don't know how to access to the static variables within the static template function. I don't want to export the class, because I want to encapsulate the logic so it's not usable from the browser.

What's the way to go here? I started with this because it wasn't static at first, but I changed my mind and I'm stuck now.

1 Answer 1

2

In this case you can just type the class name like below (so the same as you have now but without the module name (Test)

Handlebars.templates[Template.basePath + Template.templatesFolder + '/' + templateName + Template.ext];

You can't access the public static template function now from outside the module because it is in the class which isn't exported.

If you move that function out of the class in the module and instead of public static make it export function you can call it outside the module and it should work correctly.

Sign up to request clarification or add additional context in comments.

1 Comment

It was so easy, I knew it had to be possible, just forgot how to do it! Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.