zoukankan      html  css  js  c++  java
  • Functions & Closures

    Functions

    1、不带返回值的函数:

      

    2、通过tuple返回元素

      

      返回的tuple可按如下方式使用:

      

    3、External Parameter:

      

      External parameter的使用:

        

    4、Shorthand external parameter:

      

    5、Default Parameter:

      

      Default Parameter自动定义了external parameter:

      

      

    6、Variadic Parameters,变长参数,在类型后面加上...:

      

    7、Variable Parameter,函数参数默认是const,即函数body内无法改变参数值。要想在函数body内改变此值,需用var声明参数。

      

    8、In-out参数:

      

      使用in-out参数:

      

    9、FunctionType:

      

      可以在String Interpolation中调用函数:

      

    10、FuntionType as Parameter Type:

      

    11、FunctionType as Return Type:

      

    Closures

    1、三种Closure:

      

    2、Closure Expression Syntax:

      

      

    3、Inferring Type From Context

      

      在单表达式Closure的情况下,return也可以省略:

      

    4、Shorthand Argument Names,通过数字

      

    5、Operator Function

      

    6、Trailing Closure

      

      array.map使用Trailing Closure的例子:

      

    7、下述代码中,runningTotal会capture reference:

      

    8、Closure are reference types。

  • 相关阅读:
    mysql数据库 详解
    0810 smarty
    抽象类
    Nginx 负载均衡策略
    Nginx 负载均衡配置和策略
    内置Web Server
    PHP运行方式
    MySQL create table 语法
    MySQL 索引的使用
    MySQL的 explain 解析
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3789380.html
Copyright © 2011-2022 走看看