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/] ...
随机推荐
- Go 语言编译过程
走进Golang之编译器原理_大愚Talk-CSDN博客 https://blog.csdn.net/hel12he/article/details/103061921 go编译器 - 知乎 http ...
- 【转载】【网络安全】渗透中 PoC、Exp、Payload 与 Shellcode 的区别
原文地址 渗透中 PoC.Exp.Payload 与 Shellcode 的区别 概念 PoC,全称"Proof of Concept",中文"概念验证",常指 ...
- Grafana Prometheus系统监控Redis服务
Grafana Prometheus系统监控Redis服务 一.Grafana Prometheus系统监控Redis服务 1.1流程 1.2安装redis_exporter 1.3配置prometh ...
- 用友GRP-u8 SQL注入
POST /Proxy HTTP/1.1 Accept: Accept: */* Content-Type: application/x-www-form-urlencoded User-Agent: ...
- Hive 报错
hadoop hive任务失败,原因是GC overhead limit exceeded (OOM) GC Overhead Limit Exceeded error是java.lang.OutOf ...
- liux 常用操作命令
tail -f /home/jyapp/apache-tomcat-7.0.59/logs/catalina.out //查看实施日志 //删除临时目录并且启动服务器 rm -rf /home/jy ...
- JavaScript解构赋值
JavaScript解构赋值 JavaScript解构赋值为我们提供了很多方便,但是用法比较多,本文就来梳理一下.总体来说,主要就两种地方使用解构赋值,一种是数组的解构赋值,另一种是对象的解构赋值.以 ...
- TypeScript 的 Substitutability
Substitutability 中文含义是 可代替性,这个词我未在 TypeScript 的语言特性相关文档上看到,百度.谷歌搜索也寥寥无几.仅在TypeScript FAQ 找到相关描述. 有关类 ...
- Malaysia Trip Memory ('-ωก)
独白 初次见面,睡意阑珊.日轮.稀疏.惨白色.墨绿色,\(\rho_{atm}>\rho_{space}\) 的作用被赤道所隐藏,一时的不知所从,斑斓成了单一.之后的故事,踏上一辆盛装打扮的 ...
- HttpRunner(1)自我介绍
前言 首先,我们无论学习哪个框架,都要带着问题,带着思考去学习 思考1:HttpRunner是什么? 思考2:HttpRunner的设计模式是什么? 思考3:为什么我们要学习HttpRunner?他的 ...