1. 类的定义和使用

class Student {
name; say() {
console.log(this.name + " saying");
}
} var s1 = new Student();
s1.name = "zhangsan";
s1.say(); var s2 = new Student();
s2.name = "lisi";
s2.say();

  

2. 类的构造函数

class Student {

    constructor(name: string) {
this.name = name;
} name; say() {
console.log(this.name + " saying");
}
} var s1 = new Student("zhangsan");
s1.say(); var s2 = new Student("lisi");
s2.say();

 类的构造函数定义在constructor

效果图

上面的代码可以简写为

class Student {

    constructor(public name: string) {
} say() {
console.log(this.name + " saying");
}
} var s1 = new Student("zhangsan");
s1.say(); var s2 = new Student("lisi");
s2.say();

  输出结果是一样的

3. 类的继承

class Student {

    constructor(public name: string) {
} say() {
console.log(this.name + " saying");
}
} class HighSchoolStudent extends Student { constructor(name: string, no: string) {
super(name)
}
no:string;
study() {
super.say();
}
} var hStudent = new HighSchoolStudent("wangwu","06169020");
hStudent.say();

  

extends 代表要继承的类

super(name)调用父类的构造函数

super.say(); 调用父类的方法

Typescript学习总结之类的更多相关文章

  1. TypeScript学习指南--目录索引

    关于TypeScript: TypeScript是一种由微软开发的自由和开源的编程语言.它是JavaScript的一个超集,而且本质上向这个语言添加了可选的静态类型和基于类的面向对象编程. TypeS ...

  2. TypeScript 学习一 参数,函数,析构表达式

    1,TypeScript是由谷歌开发的,并且新出的Angular2框架就是谷歌公司由TypeScript语言编写的,所以现在TypeScript是有微软和谷歌一起支持的: 2,TypeScript在j ...

  3. TypeScript 学习资料

    TypeScript 学习资料: 学习资料 网址 TypeScript Handbook(中文版)(推荐) https://m.runoob.com/manual/gitbook/TypeScript ...

  4. Typescript 学习笔记七:泛型

    中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...

  5. Typescript 学习笔记六:接口

    中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...

  6. Typescript 学习笔记五:类

    中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...

  7. Typescript 学习笔记四:回忆ES5 中的类

    中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...

  8. Typescript 学习笔记二:数据类型

    中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...

  9. Typescript 学习笔记三:函数

    中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...

  10. Typescript 学习笔记一:介绍、安装、编译

    前言 整理了一下 Typescript 的学习笔记,方便后期遗忘某个知识点的时候,快速回忆. 为了避免凌乱,用 gitbook 结合 marketdown 整理的. github地址是:ts-gitb ...

随机推荐

  1. json_encode 处理后的数据是null

    原因: json_encode($str) 中的字符串 必须是 utf-8的格式: -------------------------------- 问题描述: 返回的json数据: <?php ...

  2. 24点小游戏app宣传文案

    24点小游戏app宣传文案 游戏背景 24点小游戏是传统的扑克牌游戏,是通过扑克牌来完成的竞争性智力游戏,除了希望能够消磨我们的空闲时间,加强同学们的临机和速算能力,还能够促进我们每个人的大脑和逻辑性 ...

  3. sqlite的数据类型

    参考sqlite官方文档:https://www.sqlite.org/datatype3.html 绝大多数的SQL数据库采用静态的.严格的数据类型,数据库中的值由数据表的列类型定义决定. 然而,s ...

  4. (Object String 类中的方法练习)

    package com.zs.demo1; public class Demo1 { public static void main(String[] args) { fun1(); fun2(); ...

  5. Java技术体系

    Shell 解释型编程语言(脚本语言都是解释型语言) Shell通过解释器/bin/bash 解释,运行在进程中 Java 编译型解释型语言(先编译再解释) Java通过编译器转换成字节码语言,再用过 ...

  6. [转]ZooKeeper 集群环境搭建 (本机3个节点)

    ZooKeeper 集群环境搭建 (本机3个节点) 是一个简单的分布式同步数据库(或者是小文件系统) ------------------------------------------------- ...

  7. thinkphp 参数传递方式(基础)

    我今天下午主要学习了thinkphp5.0的路由部分,我下面总结一下我主要学习到的知识点: 路由定义: 有两种方式: (1).动态注册: eg: Route::rule('hello','index/ ...

  8. ORA-15025 搭建DG环境,restore controlfile报错,提示oracle无法使用ASM存储

    环境说明: #主库RAC环境 #备库RAC环境,操作系统AIX 6.1 数据库版本11.2.0.3 报错说明: #主库备份控制文件,传输至备库,备库restore 报错 本篇文档,分为两大阶段:第一阶 ...

  9. Ubuntu下设置开机后自动运行命令

    从道理上来讲,ubuntu开机应该是能够设置执行一些脚本的,事实上确实如此,网上给出了很多解决的方案,基本上是分为两种, 第一种是编辑/etc/下的rc.local脚本,

  10. ssh和ejb的区别

    转自:https://zhidao.baidu.com/question/137154342.html SSH(Struts,Spring,Hibernate) Struts进行流程控制,Spring ...