当前位置:网站首页>Typescript 命名空间
Typescript 命名空间
2022-08-08 05:22:00 【-耿瑞-】
命名空间的作用主要就是防止同名方法或函数 主要就是多做一块作用于
我们先来看一段代码
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}`)
}
}
}
这里我们定义了两个命名空间 padd 和 bfsl 在他们下面都有一个叫dog的类 而这不会冲突也不会覆盖 因为他们在不同的命名空间中
而现在我们就用命名空间来实例化这两个类 然后调用他们中的signUp方法
var paddDog = new padd.dog("狗狗");
var bfslDog = new bfsl.dog("大黄");
这里可以看到 我们 取出命名空间的方法非常简单 命名空间名.类名
然后我们用实力对象调用其中的方法signUp
paddDog.signUp();
bfslDog.signUp();
运行结果如下
没有任何问题
以下操作都是在同一文件 如果不在同一文件 需要用导入导出 调用方法 仍是 命名空间.类名
边栏推荐
猜你喜欢
随机推荐
The shell updates the terminal output information in place
【多任务CTR】阿里ESMM:Entire Space Multi-Task Model: An Effective Approach for Estimating Post-Click Conve
Go-Excelize API源码阅读(十)—— SetActiveSheet(index int)
Personal Summary of OLTP and OLAP Issues
LVS:NAT模式详解
多维度数组拉平到一维
Session and cookie usage
The difference between CHAR_LENGTH() and LENGTH() in MySQL
reduce具体使用以及使用reduce,toString,flat进行数组降维
Sequence table (below)
tracepoint: 定义函数及调用示例
BMS 产品功能和详细设计规格
【冷启动】快手《POSO: Personalized Cold Start Modules for Large-scale Recommender Systems》
IP核之RAM实验
KDD‘22推荐系统论文梳理(24篇研究&36篇应用论文)
After being unemployed for 6 months at home, I bought a house with full payment through outsourcing: the industries you look down on are often very profitable
Unity-CharacterController (Character Controller)
postman---postman parameterization
C language - score and loop statement
使用 Zap 和 W3af 进行 Web 应用程序漏洞评估









