当前位置:网站首页>TypeScript-命名空间
TypeScript-命名空间
2022-06-11 07:54:00 【YY小怪兽】
详情可见
1.什么是命名空间?
命名空间可以看做是一个微型模块,
当我们先把相关的业务代码写在一起, 又不想污染全局空间的时候, 我们就可以使用命名空间
本质就是定义一个大对象, 把变量/方法/类/接口...的都放里面
2.命名空间和模块区别
在程序内部使用的代码, 可以使用命名空间封装和防止全局污染
在程序内部外部使用的代码, 可以使用模块封装和防止全局污染
总结: 由于模块也能实现相同的功能, 所以大部分情况下用模块即可
namespace Validation {
const lettersRegexp = /^[A-Za-z]+$/;
export const LettersValidator = (value) =>{
return lettersRegexp.test(value);
}
}
console.log(Validation.LettersValidator('abc'));
console.log(Validation.LettersValidator(123));
调用其他位置的命名空间的方法
./56/test.ts
namespace Validation {
const lettersRegexp = /^[A-Za-z]+$/;
export const LettersValidator = (value) =>{
return lettersRegexp.test(value);
}
}
/// <reference path="./56/test.ts" />
console.log(Validation.LettersValidator('abc'));
console.log(Validation.LettersValidator(123));
边栏推荐
- TiDB Cloud 上线 Google Cloud Marketplace,以全新一栈式实时 HTAP 数据库赋能全球开发者
- 【集群】haproxy负载均衡
- 放大镜子效果图
- multi-sig SC
- Sort - select sort
- Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]
- A correction book full of sad tears
- Deux diplômés, la Banque a externalisé le travail d'essai pendant plus de quatre mois. Parler de vrais sentiments...
- Sort - Swap sort
- 签到体系设计:签到功能该怎么画
猜你喜欢

2022.6.6 特长生模拟

Printing diamond of beginner C

学习《缠解论语》

Tidb cloud launched Google cloud marketplace, empowering global developers with a new stack of real-time HTAP databases

Figure seamless database integration tushare interface

Bladed入門教程(視頻)

Batch splice string

Detailed explanation of shift operator and bit operator in C language

Zero foundation self-study SQL course | outer join external connection

Implementation of stack (C language)
随机推荐
Image processing operation record
C language - Growth Diary -02- function
Paging of the flask page
2. Graduated from this course, and the bank has outsourced testing work for more than 4 months. Talk about some real feelings
Sort - Swap sort
Tidb Cloud est en ligne sur le marché Google Cloud pour permettre aux développeurs du monde entier d'utiliser une nouvelle pile de bases de données htap en temps réel
Import on CSDN MD file
Simple use of string
ConstraintLayout中使用Guideline限制控件最大宽度
About static keyword
学习《缠解论语》
[IOT] project management: how to build a better cross functional team?
Use of wordcloud
彻底记住ImageView的background和src的区别
【AtCoder2304】Cleaning
Sort - merge sort
Detailed explanation of character function and string function (including simulation implementation)
【案例解读】医疗单据OCR识别助力健康险智能理赔
134. gas station
Socket [5] - struct linker usage