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/] ...
随机推荐
- WPF学习里程(二) XAML基础
1.什么是XAML? 官方语言: XAML是eXtensible Application Markup Language的英文缩写,相应的中文名称为可扩展应用程序标记语言,它是微软公司为构建应用程序用 ...
- mysql和oracle的字符拼接方法
不同的数据库,相应的字符串拼接方式不同,通过对比加深一下记忆. 一.MySQL字符串拼接 1.CONCAT函数 语法格式:CONCAT(char c1, char c2, ..., char cn) ...
- OIer 生涯绊脚石
字符串 哈希进制搞质数 \({\color{OrangeRed}{KMP}}\) 数组别开太大,否则 \({\color{Gold}{TLE}}\) 没有必要 \({\color{Cyan}{strl ...
- Web信息收集-目标扫描-OpenVAS
Web信息收集-目标扫描-OpenVAS 一.OpenVAS简述 二.部署OpenVAS 2.1 升级Kali Linux 2.2 安装OpenVAS 2.3 修改admin账户密码 2.4 修改默认 ...
- fedora 20安装vim Transaction check error
Transaction check error安装时 yum remove vim-minimal 再安装vim ok
- Openstack (keystone 身份认证)
keystone简介 keystone 是OpenStack的组件之一,用于为OpenStack家族中的其它组件成员提供统一的认证服务,包括身份验证.令牌的发放和校验.服务列表.用户权限的定义等等.云 ...
- apache和LAMP架构
资源池: httpd依赖包:apr 和 apr-util 下载:点击这里 httpd 下载:点击这里 mysql 下载:点击这里 php 下载: 点击这里 本章资源: 点击这里 资源提取码:u2jv ...
- c++nullptr(空指针常量)、constexpr(常量表达式)
总述 又来更新了,今天带来的是nullptr空指针常量.constexpr(常量表达式)C++的两个用法.Result result_fun = nullptr;constexpr stati ...
- Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) C. Remove Adjacent(字符串,贪心,枚举)
题意: 给你一个由小写字母组成的字符串,若串中两个相邻元素字典序中也相邻,移除较大字母,问最多能移除多少个字母. 思路: 从大到小依次枚举. Tips: 注意下标的处理. 以小消大: #include ...
- P3376 [模板] 网络最大流
https://www.luogu.org/blog/ONE-PIECE/wang-lao-liu-jiang-xie-zhi-dinic EK 292ms #include <bits/std ...