namespace

// 基础使用导出、嵌套、合并、抽离、简化
namespace Test {
  let c = 6
  export let b = 5
  export const f = () => 1
  // 嵌套的namespace也是要export,才能被外部引用
  export namespace Test1 {
    export let d = 6
  }
}
namespace Test {
  export let e = 8
}
// 必须导出才能被使用
console.log(Test.b);
console.log(Test.f);
// console.log(Test.c); // 报错
// 调用嵌套的namespace
console.log(Test.Test1.d); 
// 同名namespace自动合并
console.log(Test.e);

// 抽离可以直接import别的是文件中export的namespace
import { fn1 } from './fn'
console.log(fn1.g);

// 简化
import g = fn1.g
console.log(g);

// 实例,多端开发时,每个端需要调用的方法和参数都不一样,可以根据namespace去定义
namespace ios {

}
namespace Android {

}

 

posted on 2025-02-16 00:51  ChoZ  阅读(10)  评论(0)    收藏  举报

导航