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/] ...
随机推荐
- spring 之7种重要设计模式
Spring中涉及的设计模式总结 1.简单工厂(非23种设计模式中的一种) 实现方式: BeanFactory.Spring中的BeanFactory就是简单工厂模式的体现,根据传入一个唯一的标识来获 ...
- 基于nginx的频率控制方案思考和实践
基于nginx的频率控制方案思考 标签: 频率控制 nginx 背景 nginx其实有自带的limit_req和limit_conn模块,不过它们需要在配置文件中进行配置才能发挥作用,每次有频控策略的 ...
- Python基础(函数)
为什么要用函数? 解决代码重用问题 统一维护 程序的组织结构清晰,可读性强函数:先定义后使用1.内置函数 built-in function eg:sum max len2.自定义函数:定义有参函数 ...
- .Net 5 C# 反射(Reflection)
这里有个目录 什么是反射 有什么用?怎么用? 获取类型的类型信息. 获取泛型信息 获取程序集的信息 从已加载的程序集获取 Type 对象 查看类的信息 首尾呼应.重复强调.重要事情说三遍 后记 什么是 ...
- 《CSP.OI吟》
吟 CSP·OI 这个LCT,我听得很懵逼 在 Splay 里面,好像有重链 不用线段树,Splay 来维护 树的形态有改变,不只是那一条边 所以要把整棵树,重新剖一遍 什么重链 ~ 什么轻边 ~ 什 ...
- FLOYD判圈
转载一篇博客:http://blog.csdn.net/javasus/article/details/50015687 Floyd判圈算法(Floyd Cycle Detection Algorit ...
- 内网渗透之信息收集-linux
linux 系统信息 grep MemTotal /proc/meminfo #查看系统内存总量 cat /etc/issue #查看系统名称 ...
- 后台获取日期值,前台Js对日期进行操作
需求描述: 方法一: 方法二: 一些标签常用隐藏方法: 需求描述: 在初始化页面的时候,需要根据系统当前的时间对前台JSP页面的某项进行值的初始化,若前台JSP标签没有相关可以初始化的属性,那么可以从 ...
- springsecurity教程一
可以看这个人的springsecurity省的自己写了 1.springsecurity学习目标 2.1 springsecurity简介 2.2 springsecurity快速入门demo 1): ...
- Redis命令之setbit
setbit的作用是,对key上存储的字符串,设置或清除指定偏移量上的位(bit). 语法如下: SETBIT key offset value key是要操作的对象的键. offset是操作对象上的 ...