When multiple decorators apply to a single declaration, their evaluation is similar to function composition in mathematics. In this model, when composing functions f and g, the resulting composite (f ∘ g)(x) is equivalent to f(g(x)).

As such, the following steps are performed when evaluating multiple decorators on a single declaration in TypeScript:

  1. The expressions for each decorator are evaluated top-to-bottom.
  2. The results are then called as functions from bottom-to-top.

If we were to use decorator factories, we can observe this evaluation order with the following example:

  1. function f() {
  2. console.log("f(): evaluated");
  3. return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
  4. console.log("f(): called");
  5. }
  6. }
  7.  
  8. function g() {
  9. console.log("g(): evaluated");
  10. return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
  11. console.log("g(): called");
  12. }
  13. }
  14.  
  15. class C {
  16. @f()
  17. @g()
  18. method() {}
  19. }
  20.  
  21. /*
  22.  
  23. f(): evaluated
  24. g(): evaluated
  25. g(): called
  26. f(): called
  27.  
  28. */

[ES7] Descorator: evaluated & call order的更多相关文章

  1. Fedora 24中的日志管理

    Introduction Log files are files that contain messages about the system, including the kernel, servi ...

  2. SH Script Grammar

    http://linux.about.com/library/cmd/blcmdl1_sh.htm http://pubs.opengroup.org/onlinepubs/9699919799/ut ...

  3. bash内部命令-2

    http://www.gnu.org/software/bash/ http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/ [root@250-shiyan ~]# ...

  4. [Hive - LanguageManual] Create/Drop/Alter -View、 Index 、 Function

    Create/Drop/Alter View Create View Drop View Alter View Properties Alter View As Select Version info ...

  5. zonghe

      package hcxAction; import hcxMode.Advertises; import hcxMode.Areas; import hcxMode.Saveresume; imp ...

  6. Load PE from memory(反取证)(未完)

      Article 1:Loading Win32/64 DLLs "manually" without LoadLibrary() The most important step ...

  7. Bash基本功能

    bash的基本功能 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 欢迎加入:   高级运维工程师之路               598432640 一.历史命令和命令补全 1.历 ...

  8. MemoryModule -- load a DLL completely from memory

    https://github.com/fancycode/MemoryModule MemoryModule is a library that can be used to load a DLL c ...

  9. Zipline Beginner Tutorial

    Zipline Beginner Tutorial Basics Zipline is an open-source algorithmic trading simulator written in ...

随机推荐

  1. 这是从word发的第一篇博客。

    喜欢做的事,怎么样都不会厌倦. 以前只知道office功能强大,但不太清楚到底还能干些啥,印象最深的是outlook了,自己也在用,挺好 今天偶然发现,word还能发布博客,真是太惊喜了 这算是一篇实 ...

  2. 个人笔记--struts2对Action的权限拦截

    一.编写一个类实现com.opensymphony.xwork2.interceptor.Interceptor 接口 PermissionInterceptor.java <pre name= ...

  3. Word删除空白页

    1.常见的就是在前一页最后按delete 2.我遇到的问题是,共两页第一页是平常的A4,是表格,第二页也是A4,只不过横着显示(后来才知道的),中间是分节符,不能直接删除的,否则表格各个部分分开在好几 ...

  4. 【技术贴】解决Mysql启动服务报错1067 进程意外终止

    无法启动MYSQL服务错误1067 进程意外终止. 我使用2013-10-25_appserv-win32-2.6.0.exe安装的MySql,结果服务起不来. 于是细心机智的我发现,在F:\stud ...

  5. GSM、GPRS、EDGE、2G、3G与WAP的关系

    1.GSM(Global System of Mobile communication)即全球移动通讯系统: 是目前使用人数最大的移动通信网络,就是2G的移动通信技术,是一种电路交换系统.这种网络仅提 ...

  6. Android 观察系统中短信内容的变化(内容观察者)

    //内容观察者(如果系统的短信发生了变化,比如刚获取一条短信,那么将触发onChange方法) ContentResolver contentResolver = getContentResolver ...

  7. Eclipse下设置github开发环境

    1.按照github上的指南配置(http://help.github.com/win-set-up-git/)基础的git环境. 2.在github上创建一个Repository. 3.在Eclip ...

  8. SharedPreference.Editor的apply跟commit方法的異同

    相同点: 1.二者都可提交preference的修改数据 2.二者都是原子操作 区别: 1.apply没有返回值而commit返回boolean表明修改是否提交成功 2.apply是将修改数据原子提交 ...

  9. [cocos2dx动作]CCLabel类数字变化动作

    cococs2dx的CCLabel类的数字变化动作 介绍: 简单的数字变化动作(适用于CCLabel类对象, 包括CCLabelTTF, CCLabelAtlas, CCLabelBMFont等等) ...

  10. 三星 PMU NXE2000,x-powers的AXP228,NXE2000

    核心板PMIC X4418CV2并没有用三星推荐的PMU NXE2000,而是自主研发,采用x-powers的AXP228,这是因为AXP228更符合用户的习惯,更适合做产品,他们有如下区别: PMU ...