当前位置:网站首页>Typescript namespace
Typescript namespace
2022-08-08 05:24:00 【-Geng Rui-】
The role of namespace is mainly to prevent methods or functions with the same name The main thing is to do more
我们先来看一段代码
namespace padd {
export class dog {
name:String;
constructor(name:String){
this.name = name;
}
signUp(){
console.log(`我的名字叫${
this.name}`)
}
}
}
namespace bfsl {
export class dog {
name:String;
constructor(name:String){
this.name = name;
}
signUp(){
console.log(`请叫我${
this.name}`)
}
}
}
Here we define two namespaces padd 和 bfsl Below them all have a calldog的类 And that doesn't conflict or overwrite because they are in different namespaces
Now we use namespaces to instantiate these two classes Then call one of themsignUp方法
var paddDog = new padd.dog("狗狗");
var bfslDog = new bfsl.dog("大黄");
这里可以看到 我们 The way to take out the namespace is very simple 命名空间名.类名
Then we call the methods on it with the strength objectsignUp
paddDog.signUp();
bfslDog.signUp();
运行结果如下
没有任何问题
The following operations are all in the same file if not in the same file need to use import and export 调用方法 仍是 命名空间.类名
边栏推荐
猜你喜欢
随机推荐
Hundreds of billions, large-scale: performance tuning practice of Tencent's super-large Apache Pulsar cluster
C language framework FreeSwitch custom event introduction and usage example
Use of Filter
【无标题】暂时没有想好叫什么名字
CAP定理实例分析
Leetcode78. 子集
千亿级、大规模:腾讯超大 Apache Pulsar 集群性能调优实践
Single host docker builds redis-cluster
Connect two tables to update the third table (updata) in postgresql
Personalized use of Qt log module
L3-006 Slash in the wind
Filter 过滤器的使用
10 must-have free tools for self-media people to operate quickly and efficiently
28.异常检测
B. Reverse Binary Strings
Week 8 Generative Adversarial Networks(生成对抗网络 GAN)
nonebot插件:说话的艺术
gcc/g++使用
76. 最小覆盖子串
C语言力扣第58题之最后一个单词的长度。从后往前遍历









