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.





  • 相关阅读:
    【Todo】CSDN的《问底》系列-学习
    【Todo】深入PHP内核系列
    【转载】网络攻击技术(三)——Denial Of Service & 哈希相关 & PHP语言 & Java语言
    回溯法
    hdu 2842 Chinese Rings
    JSP 9 大内置对象详解
    用Html5结合Qt制作一款本地化EXE游戏-太空大战(Space War)
    HDU2795 billboard【转化为线段树。】
    URAL 1303
    IOS文件沙盒
  • 原文地址:https://www.cnblogs.com/FBsharl/p/10153819.html
Copyright © 2011-2022 走看看