[TypeScript] Create a fluent API using TypeScript classes
You can create an easy to chain API using TypeScript classes. Learn about the this
return type annotation and how it plays with function chaining and class inheritance.
class Adder {
protected acc: number = ;
add(num: number): Adder {
this.acc += num;
return this; // enable to chain methods
} get result() {
return this.acc;
}
} const adder = new Adder()
const res = adder.add().add().result;
console.log(res); // class Calculator extends Adder {
subtract(num: number): Calculator {
this.acc -= num;
return this;
}
} const cal = new Calculator();
const res2 = cal.add().add().subtract().result;
console.log(res2) // -97
You can also do:
const res2 = new Calculator()
.add()
.add()
.subtract()
.result;
console.log(res2) // -97
[TypeScript] Create a fluent API using TypeScript classes的更多相关文章
- [Vuex] Create a Vuex Store using TypeScript
A Vuex store centralizes the state of your app, making it easy to reason about your state flow. In t ...
- [TypeScript] Create random integers in a given range
Learn how to create random integers using JavaScript / TypeScript. /** * Returns a random int betwee ...
- 1.【使用EF Code-First方式和Fluent API来探讨EF中的关系】
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/relationship-in-entity-framework-using-code-firs ...
- [转]Entity Framework Fluent API - Configuring and Mapping Properties and Types
本文转自:https://msdn.microsoft.com/en-us/data/jj591617#1.2 When working with Entity Framework Code Firs ...
- Entity Framework Code-First(10):Fluent API
Fluent API in Code-First: We have seen different DataAnnotations attributes in the previous sections ...
- 8.Fluent API in Code-First【Code-First系列】
在前面的章节中,我们已经看到了各种不同的数据注解特性.现在我们来学习一下Fluent API. Fluent API是另外一种配置领域类的方式,它提供了更多的配置相比数据注解特性. Mappings[ ...
- EF框架step by step(9)—Code First Fluent API
在上一篇中,讲述了用数据特性的方式来标识实体与数据表之间的映射关系,在Code First方法中,还可以通过Fluent API的方式来处理实体与数据表之间的映射关系. 要使用Fluent API必须 ...
- 002.Create a web API with ASP.NET Core MVC and Visual Studio for Windows -- 【在windows上用vs与asp.net core mvc 创建一个 web api 程序】
Create a web API with ASP.NET Core MVC and Visual Studio for Windows 在windows上用vs与asp.net core mvc 创 ...
- 一起学ASP.NET Core 2.0学习笔记(二): ef core2.0 及mysql provider 、Fluent API相关配置及迁移
不得不说微软的技术迭代还是很快的,上了微软的船就得跟着她走下去,前文一起学ASP.NET Core 2.0学习笔记(一): CentOS下 .net core2 sdk nginx.superviso ...
随机推荐
- caffe 在 windows 下的配置(scripts\build_win.cmd)
官网配置文档见:GitHub - BVLC/caffe at windows 1. windows 设置 requirements: visual studio 2013/2015 CMake > ...
- Mybatis like查询的写法--转载
原文地址:http://lavasoft.blog.51cto.com/62575/1386870 Mybatis like查询官方文档没有明确的例子可循,网上搜索了很多,都不正确. Mybatis ...
- VUE笔记 - 品牌后台 - v-for Splice Some Filter findIndex indexOf 直接return函数结果
<body> <div id="app"> <div class="panel panel-primary"> <di ...
- COGS——C2274. [HEOI 2016] tree
http://www.cogs.pro/cogs/problem/problem.php?pid=2274 ★☆ 输入文件:heoi2016_tree.in 输出文件:heoi2016_tre ...
- Project Euler 613 Pythagorean Ant(概率+积分)
题目链接:点击我打开题目链接 题目大意: 给你一只蚂蚁,它在一个 边长为 \(30-40-50\) 的直角三角形\((x,y)\)上,并且它在直角三角形中选择的位置和移动方向的概率都是相等的.问你这只 ...
- JS学习笔记 - 微博发布效果
<script> window.onload = function() { var oTxt = document.getElementById('txt1'); var oBtn = d ...
- (转)kvm虚拟机中,如何给子系统更换光盘
转自:http://www.cnblogs.com/york-hust/archive/2012/06/12/2546334.html 启动kvm后,在kvm窗口中,按下CTRL+ALT+2,切换至q ...
- 常用到的Linux命令
记录一下日常用到的Linux命令,就当做日志了 1.查看Linux 端口号 netstat -apn | grep 80 2.杀死进程 kill -s 9 pid (tomcat 启动不起来有可 ...
- Android java.lang.IllegalArgumentException: Object returned from onCreateLoader must not be a non-static inn
AsyncTaskLoader: http://developer.Android.com/intl/zh-CN/reference/android/content/AsyncTaskLoader.h ...
- UVA 10603 - Fill BFS~
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&c ...