我可以在打字稿中声明静态私有函数吗? [英] Can I declare a static private function in typescript?

查看:53
本文介绍了我可以在打字稿中声明静态私有函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

module Dialog {
    export class Modal {
        static createAccessModal(link: Link) {
            createModal(link);
        }
        static createAdminModal(link: Link) {
            link.Modal.MaxHeight = 600;
            link.Modal.Width = false;
            createModal(link);
        }
        static private createModal(link: Link) {

            ...
        }
    }
}

我不想被允许直接调用createModal,所以我试图将其设为私有.当我使用智能感知时,它会在其上显示一个小锁符号,但是当我使用它时,它不会给出任何错误.还有其他方法可以做到这一点.这是我调用该函数的方式:

I don't want to be allowed to call createModal directly so I tried to make it private. When I use intellisense it shows up with a small lock symbol against it but then it doesn't give any error when I use it. Is there some other way I could do this. Here is how I call the function:

Dialog.Modal.createAccessModal(link); // I want this to be allowed
Dialog.Modal.createModal(link); // I don't want this to be allowed

顺便说一句,我对所有事物都使用静态函数,因为这些函数除了在屏幕上创建对象外没有其他作用,然后对象会自己照顾自己,因为它们具有自己的提交按钮等.这是合理的做法吗??

By the way I am using static functions for everything as these functions do nothing other than create objects on the screen and then the objects take care of themselves as they have their own submit button etc. Is this a reasonable thing to be doing?

推荐答案

module Dialog {
    export module Modal {
        export function createAccessModal(link: Link) {
            createModal(link);
        }
        export function createAdminModal(link: Link) {
            link.Modal.MaxHeight = 600;
            link.Modal.Width = false;
            createModal(link);
        }
        function createModal(link: Link) {

            ...
        }
    }
}

这篇关于我可以在打字稿中声明静态私有函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆