Typescript & classes & public shorthand
classes & public shorthand
Also of note, the use of
public
on arguments to the constructor is a shorthand that allows us to automatically create properties with that name.
http://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html#classes
with public
class Student {
fullName: string;
constructor(public firstName: string, public middleInitial: string, public lastName: string) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
interface Person {
firstName: string;
lastName: string;
}
function hello(person: Person) {
// return "Hello, " + person.firstName + " " + person.lastName;
let {
firstName,
lastName,
} = person;
return `Hello, ${firstName} ${lastName}`;
}
let student = new Student("xgqfrms", "X.", "webgeeker");
let log = console.log;
log(student.firstName);
log(student.middleInitial);
log(student.lastName);
log(hello(student));
// document.body.innerHTML = hello(student);
no public
class Student {
fullName: string;
firstName: string;
middleInitial: string;
lastName: string;
/// no public
constructor(firstName: string, middleInitial: string, lastName: string) {
this.firstName = firstName;
this.middleInitial = middleInitial;
this.lastName = lastName;
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
interface Person {
firstName: string;
lastName: string;
}
function hello(person: Person) {
// return "Hello, " + person.firstName + " " + person.lastName;
let {
firstName,
lastName,
} = person;
return `Hello, ${firstName} ${lastName}`;
}
let student = new Student("xgqfrms", "X.", "webgeeker");
let log = console.log;
log(student.firstName);
log(student.middleInitial);
log(student.lastName);
log(hello(student));
// document.body.innerHTML = hello(student);
Typescript & classes & public shorthand的更多相关文章
- TypeScript - Classes
简介 JavaScript语言基于函数和原型链继承机制的方式构建可重用的组件.这对于OO方面编程来说显得比较笨拙.在下一代的JavaScript标准ECMAScript 6为我们提供了基于class ...
- [TypeScript] Create a fluent API using TypeScript classes
You can create an easy to chain API using TypeScript classes. Learn about the thisreturn type annota ...
- TypeScript constructor public cause duplicate bug
TypeScript constructor public cause duplicate bug constructor public const log = console.log; // con ...
- [TypeScript] Export public types from your library
If you're a library author, it's useful to expose your public types as interfaces, to allow your con ...
- [TypeScript] Creating a Class in TypeScript
Typescript classes make traditional object oriented programming easier to read and write. In this le ...
- [TypeScript] Sharing Class Behavior with Inheritance in TypeScript
Typescript classes make inheritance much easier to write and understand. In this lesson we look into ...
- TypeScript 小记
1. 对比JavaScript TypeScript是JavaScript的超集,可编译为JavaScript,主要提供类型系统等增强代码的可读性和可维护性,适合中大型项目多人协作: TypeScri ...
- Public Private Protect Inheritance and access specifiers
In the previous lessons on inheritance, we've been making all of our data members public in order to ...
- Replacing the deprecated Java JPEG classes for Java 7
[src: https://blog.idrsolutions.com/2012/05/replacing-the-deprecated-java-jpeg-classes-for-java-7/] ...
随机推荐
- C++ Primer Plus读书笔记(八)函数探幽
1.内联函数 inline int square(x) {return x*x} 2.引用变量 int& 中的& 不是地址运算符,就想定义指针时的char* 一样,int&指的 ...
- Dos命令思维导图
通过思维导图的方式,总结常用Dos命令. 各种思维导图下载地址
- OpenStack (nova 计算服务)
nova介绍 Nova 负责维护和管理云环境的计算资源,Nova这个模块很重要,可以说是 OpenStack 的最核心的服务模块之一,以至于在 OpenStack 的初期版本里大部分的云系统管理功能都 ...
- 37.Samba 文件共享服务1--配置共享资源
1.Samba 服务程序的主配置文件包括全局配置参数和区域配置参数.全局配置参数用于设置整体的资源共享环境,对里面的每一个独立的共享资源都有效.区域配置参数则用于设置单独的共享资源,且仅对该资源有效. ...
- 2020第十一届蓝桥杯第二场JavaB组
第一题:门牌制作(624) 题目大意: 判断1到2020里面共有多少个'2': 解析: 本题简而言之就是找'2'这一个数 第一种方法:遍历将其转换为字符然后再遍历寻找 第二种方法:直接用数值的方法进行 ...
- php之PDOStatement::execute数组参数带有键值会出错
当预处理的SQL语句是用问号占位符时,如果是用数组传参的,数组里不要带有键值,否则无法执行SQL. 出错的代码如下: $test = new PDODB(); $param=["d" ...
- 自定义 ocelot 中间件输出自定义错误信息
自定义 ocelot 中间件输出自定义错误信息 Intro ocelot 中默认的 Response 中间件在出错的时候只会设置 StatusCode 没有具体的信息,想要展示自己定义的错误信息的时候 ...
- VScode 连接虚拟机
VScode 连接虚拟机 在VScode上面使用SSH连接虚拟机,编写代码以及运行都将会方便许多 打开VScode,安装Remote-SSH插件 配置SSH连接信息 点击左侧第四个图标,然后单击设置按 ...
- Codeforces Round #626 (Div. 2) B. Count Subrectangles
题目连接:https://codeforces.com/contest/1323/problem/B 题意:给一个大小为n的a数组,一个大小为m的b数组,c数组是二维数组c[i][j]=a[i]*b[ ...
- 2018 ccpc吉林 The Tower
传送门:HDU - 6559 题意 在一个三维空间,给定一个点和他的三维速度,给定一个圆锥,问这个点最早什么时候能撞上圆锥. 题解 本来一直想着怎么求圆锥的方程,然后....队友:这不是二分吗!然后问 ...