当前位置:网站首页>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 调用方法 仍是 命名空间.类名
边栏推荐
- 《动机与人格》笔记(一)——人类似乎从来就没有长久地感到过心满意足
- postman---postman parameterization
- 硬盘基础知识
- 力扣84 双周赛 t4 6144 和力扣305周赛t4 6138
- tracepoint: 定义函数及调用示例
- 0 dictionary tree/string medium LeetCode676. Implement a magic dictionary
- Week 8 Transformer Language Models and Implications
- Week 8 Generative Adversarial Networks
- KMP和EXKMP(Z函数)
- The shell updates the terminal output information in place
猜你喜欢

Connect two tables to update the third table (updata) in postgresql

TSF微服务治理实战系列(二)——服务路由

Session and cookie usage

Rust开发——Struct使用示例

spark入门学习-3-SparkSQL数据抽象

IP核之RAM实验

The only OpenCyphal/UAVCAN tutorial in the whole network (11) Write a Cyphal protocol parsing tool with candump and gawk tools

Sqlmap + dnslog injection of repetition

The fledgling Xiao Li's 115th blog project notes on the creation of the domestic GD32F103RCT6 basic project

Entering the world of audio and video - RGB and YUV formats
随机推荐
MYSQL导出数据字典
说说Redis分布式锁的原理和实现蚂【蚁金服三面】
Week 9 10 Neural Networks
Unity-CharacterController (Character Controller)
postman---postman参数化
使用ffmpeg解码音频sdl(push)播放
[Redis] Redis Learning - Transaction
postman---postman parameterization
【冷启动】快手《POSO: Personalized Cold Start Modules for Large-scale Recommender Systems》
The fledgling Xiao Li's 115th blog project notes on the creation of the domestic GD32F103RCT6 basic project
Entering the world of audio and video - RGB and YUV formats
B. Reverse Binary Strings
使用 Zap 和 W3af 进行 Web 应用程序漏洞评估
查询时间内用户分布的sql语句
10 must-have free tools for self-media people to operate quickly and efficiently
L3-006 Slash in the wind
28.异常检测
0 dictionary tree/string medium LeetCode676. Implement a magic dictionary
一小时掌握vim基础用法
Use of Filter