当前位置: 首页 > news >正文

已有域名怎么建设网站昆明网站建设首选

已有域名怎么建设网站,昆明网站建设首选,网站死链接检查,手机存储wordpress工具#xff1a; PlayGround 接口 接口用来定义对象的结构和类型#xff0c;描述对象应该具有哪些属性和方法。 它仅用于声明#xff0c;而不是实现#xff1b; 这对于编写可重用的代码非常有用。它可用于#xff1a; 关键字是interface#xff0c; 注意#xff1a;它…工具 PlayGround 接口 接口用来定义对象的结构和类型描述对象应该具有哪些属性和方法。 它仅用于声明而不是实现 这对于编写可重用的代码非常有用。它可用于 关键字是interface 注意它只是作为TypeScript的一部分并不会转换为JavaScript 数组定义 interface data {[index:number]: number, }// 类型一致没有问题 let numList_1: data [1, 2, 3]; // Type string is not assignable to type number let numList_2: data [1, , 3];对象的定义 // 方式1 interface Data_1 {name: string,age: number, } let data_1: Data_1 {name: hello,age: 20, } console.log(data_1);// 方式2 interface Data_2 {name: string;age: number;// 可选属性 表示可以选择不赋值sex?: number;// 只读属性表示一旦赋值后不可修改 readonly id:number | string; } let data_2: Data_2 {name: hello,age: 20,id : 0001, } data_2.age 10; // Error: Cannot assign to id because it is a read-only property data_2.id 10; 作为类实现 interface Person {name: string;age: number;greet: () void; }// 通过implements实现接口 class Student implements Person {name: string;age: number;constructor(name: string, age: number) {this.name name;this.age age;}greet() {console.log(Hello, my name is ${this.name});} }let student new Student(ok, 20); student.greet(); // Hello, my name is ok 类 typeScript中类的使用主要通过class来创建类对象通过new来实例化类对象 支持特性 instanceof检测对象类型 访问权限public、protected和private 函数重载 继承或重写 静态成员和方法 基本的使用 class Demo {private _name: string ;private _age: number 0;// 构造函数constructor(name:string) {this._name name;} public log() {console.log(Demo 的名字为${this._name});} } let demo new Demo(demo); console.log(typeof(demo)); // object console.log(demo instanceof Demo); // true 函数重载 类的函数重载的编写方式不要直接实现 class Demo {private _name: string ;private _age: number 0;// 构造函数constructor(name:string) {//} // Error: Multiple constructor implementations are not allowed// 原因在于如果实现编译器创建对象不知道调用哪个构造函数constructor(name: string, age:number) {//} }可以通过采用声明和可选参数的方式来实现: // 实例1 class Demo {private _name: string ;private _age: number 0;// 构造函数constructor(name:string);constructor(name: string, age:number);constructor(name: string, age?:number) {this._name name;if (age) {this._age age;}} }// 实例2: class Calculator {add(a: number, b: number): number;add(a: string, b: string): string;add(a: any, b: any): any {if (typeof a number typeof b number) {return a b;} else if (typeof a string typeof b string) {return a.concat(b);} else {throw new Error(Invalid arguments);}} }const calculator new Calculator();console.log(calculator.add(1, 2)); // 3 console.log(calculator.add(Hello, World)); // Hello World继承和重写 继承的话使用extends 如果对基类中的方法重新编写就是重写 // 定义接口简单的实例可以忽略增加的话有助于理解代码和重写代码相关 interface Animal {sound(): void; }// 实现接口 class Cat implements Animal {private _breed: string;private _name: string Cat;constructor(breed: string) {this._breed breed;}// 通过get和set的方式设置对象变量属性get Name():string {return this._name;}set Name(name: string) {this._name name;}sound(): void {console.log(猫);} }// 继承 class DomesticCat extends Cat {public log() {console.log(this is DomesticCat);} }// 重写 class WildCat extends DomesticCat {sound(): void {console.log(野猫叫声);} }const domesticCat new DomesticCat(domesticCat); domesticCat.Name 短毛猫 console.log(cat Name: ${domesticCat.Name}); //cat Name: 短毛猫 domesticCat.sound(); // 猫// const wildCat new WildCat(豹猫); wildCat.sound(); // 野猫叫声注意 如果未声明访问权限public、protected和private则默认为public对于变量建议开头增加下划线_ 表示私有可以多继承只需要在extends后面添加类接口即可注意区分implements和extends前者主要用于对interface声明的方法等进行实现 而后者主要应用于已经实现后的方法进行继承或重写。 Static 静态变量或方法在类中声明后可以不通过new对象直接赋值或使用但赋值后不可在改变。 class Demo {static value: number;static getValue() {console.log(static value: ${Demo.value});} } Demo.value 10; Demo.getValue(); //static value: 10 它常用于编写单例模式注意 构造函数设置为私有以保证对象的唯一性 class Singleton {private static instance: Singleton;private constructor() {// 私有化构造函数防止外部实例化}public static getInstance(): Singleton {if (!Singleton.instance) {Singleton.instance new Singleton();}return Singleton.instance;}public greet(): void {console.log(Hello);} }// 创建单例实例 const instance1 Singleton.getInstance(); const instance2 Singleton.getInstance();console.log(instance1 instance2); // trueinstance1.greet(); // Hello instance2.greet(); // Hello const 作为常量使用在类中使用注意 只能用于修改基本数据类型和对象属性字面量不可用于修饰引用类型如果声明const 一定要记得初始化不能在构造函数或其他函数进行初始化声明以后其本质就是readonly 只读属性 class MyClass {readonly PI: number 3.14;readonly config: { name: string, age: number } { name: John, age: 25 };constructor() {// this.PI 3.14159; // 错误无法对只读属性进行重新赋值// this.config { name: Alice, age: 30 }; // 错误无法对只读属性进行重新赋值this.config.name Alice; // 正确可以修改对象字面量属性的值this.config.age 30; // 正确可以修改对象字面量属性的值}printInfo(): void {console.log(PI: ${this.PI});console.log(Name: ${this.config.name}, Age: ${this.config.age});} }const myObj new MyClass(); myObj.printInfo();// PI: 3.14 // Name: Alice, Age: 30
http://www.hkea.cn/news/14372752/

相关文章:

  • 做qq阅读网站介绍百度seo咋做
  • 有做酒席酒水网站吗备案 网站备注
  • 做网赌需要在哪些网站投广告江苏元鼎建设工程有限公司网站
  • 珠海市官网网站建设品牌南宁市住房和城乡建设部网站
  • 建设银行打印回单网站经典广告案例
  • 网站开发在线培训怎么把电脑字体导入wordpress
  • 温州网站制作要多少钱wordpress 加备案号
  • 做网站代理怎么样做公众号好还是网站好
  • 长沙企业网站建设收费住房和城乡建设局网站
  • 鞍山信息港二手房出租宁波seo外包方案
  • 两学一做山西答题网站网站托管如何收费
  • 高密做网站的价格专门做调查问卷的网站
  • 毕设代做的网站跨境电商网站建设
  • 空间商网站ip被攻击后换ip微信域名防封跳转系统
  • 南宁百度seo软件北京核心词优化市场
  • 如何让客户主动找你做网站网站开发报价
  • 在国外建设网站怎么做网站链接支付
  • 好的免费网站建站平台重庆建设集团官方网站
  • 做携程怎样的网站网页设计作品展示图片
  • 网站开发职业前景深圳公司设立
  • 海豚一键做淘宝网站固原网络推广
  • 高端网站建设 南京在线收录
  • 重庆手机网站推广方法redis网站开发教程
  • 个人网站的名字怎样提高网站打开速度慢
  • 梅州做网站需要多少钱河北省 建设执业注册中心网站
  • 在线转格式网站怎么做wordpress 图片的设置密码
  • 网站设计奖在深圳如何注册公司
  • 雷州网站开发公司网络营销的八种方式
  • 福建省网站建设有限公司哪些网站做的人比较少
  • 企业形象网站建设意义二次开发培训