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之SQL优化详解(三)
    MySQL之SQL优化详解(二)
    MySQL之SQL优化详解(一)
    RabbitMQ从入门到精通(三)
    RabbitMQ 从入门到精通(二)
    RabbitMQ 从入门到精通 (一)
    Redis 的主从复制(Master/Slave)
    Redis的事务讲解
    Linux CentOS完全卸载PHP
    Linux(CentOS7)常用命令详解
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3789380.html
Copyright © 2011-2022 走看看