日期: 2020 年 5 月 12 日第一種:函式宣告
這種方式就是使用 function 宣告乙個具名函式,特點是可以先使用後宣告
fn() // hello world!
function fn()
第二種:函式表示式
這種方式是把乙個匿名函式賦給乙個變數,必須先宣告後使用
let fn1 = function()
fn1() // hello world!
fn2() // uncaught referenceerror: cannot access 'fn2' before initialization
let fn2 = function()
第三種:通過建構函式 new 生成
使用函式物件的方式
// let 函式名 = new function(「引數...」, 」函式體」)
let fn = new function('a', 'b', 'return a +b')
fn(1, 2) // 3
js中宣告Number的五種方式
自 1 doctype html 2 html 3 head 4 meta charset utf 8 5 title js中宣告number的五種方式 title 6head 7 body 8 script 9 10方式一 最常見的方式,通過數字字面量方式宣告 11var num 123 121....
JS的三種函式宣告
js有3種方法進行函式宣告。1 function語句型別函式宣告 function test1 函式的呼叫方式 test1 2 函式的直接量形式 var test2 function 函式的呼叫方式 test2 3 建構函式式 var test3 new function a b return a ...
js的三種函式宣告
方式一 function a e,f,h 方式二 var b function 方式三 var c new function a b c alert 我是方法c.a b c 函式的呼叫 1 按照引數列表的順序賦值如 a 1,2,3 2 var testb function 這樣的方式也是可以呼叫函式...