# JS - Function and Scope ###### tags: `Language-js` ## 前言 . - function的基本概念。 - 宣告。 - argument。 - Scope and closure。 - Lexical and dynamic scope。 - function and block scope。 - hosting and closure。 - Pass value。 ## 一 Function的基本概念 ### (一) . Function的基本概念 #### 1. **函式是JS中的物件。** - 這個概念在JS中很重要,尤其會應用於Object的prototype-base的OOP上。 - 其實,JS中,除了原生型別的變數型態,都應該是屬於『object』,其中,最大的不同是傳值方式。 #### 2. 宣告法一 ```javascript= function function_name(/*-- argument --*/){ /*--- function content ---*/ } ``` #### 3. 宣告法二 : 運算式 ```javascript= var variable_name=function(/*-- argument --*/){ /*--- function content ---*/ } ``` ```javascript= var variable_name=function function_name(/*-- argument --*/){ /*--- function content ---*/ } ``` #### 4. 宣告法三 : 箭頭函式 ## 二 . Scope ### (一) . Scope #### 1 . Scope的定義 - 定義 : 是Js的『engine』搜尋變數是否存在的一種方法。 - Engine : JS語言處理程式碼的核心之一。 - JS處理程式碼的方法 :
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up