zoukankan      html  css  js  c++  java
  • JavaScript 第三章总结

    Getting functional

    function的特点

    1. function can be reused over and over
    2. much more readable
    3. function is parameterized

    如何定义一个function

    function addscore(score,score){
    body;}

    1. 首先是关键字:function
    2. 然后是函数名:addscore
    3. 之后在括号中为两个 parameter ,并且它们不需要在前面加 var, 因为 JavaScript 自动识别了它们的类型,并且为它们分配内存。

    The function does all the work of instantiating the variable for you, so you don't need to supply the var keyword in front of your parameter names

    与c语言不同的地方:

    • 函数的类型只需定义为function
    • 函数的 parameter 不需要在前面加 var
    • 函数可放在任何一个位置,不需要提前申明
      • 如果没有 return 语句,function 返回的是一个 undefined,如果有 return 语句,return 后面的内容不会被执行,将被 ignore.

    关于argument 和 parameter

    关于argument

    可以使用 value,variable 和 expression 作为 function 的 argument.

    它们的区别

    argument 和 parameter 是不同的 :You'll only define your parameters once, but you'll probably call your function with many different arguments

    关于 pass-by value

    argument 和 parameter 是通过 pass-by value 来传递的,each argument is copied into the parameter variable.

    其他

    如果 argument 的数量少于 parameter:那么少的 argument 定义为 undefined 
    如果 argument 的数量多于 parameter:那么多的 argument 将被 ignored.

    关于 variable 的 scope 和 life

    按 scope 分,可分为 global 和 local ,并且两者不会相互影响。

    如果一个 function 中有一个 local variable,那么这时候 global variable is in the shadow of local variable and be not visiblel.





  • 相关阅读:
    js 数组去重求和 (转载)
    表格插件汇总(转载)
    SQL Server 用一张表的数据更新另一张表的数据(转载)
    C#创建DataTable(转载)
    C# DataTable 和List之间相互转换的方法(转载)
    维度表,实体表,事实表之间的关系
    Scala中foldLeft的总结
    Scala集合Map
    从合并两个Map说开去
    UDAF(用户自定义聚合函数)求众数
  • 原文地址:https://www.cnblogs.com/FBsharl/p/10153819.html
Copyright © 2011-2022 走看看