一, 箭頭函式是匿名函式不能作為建構函式不能使用new
let
fun=()
=>
let f =
newfun()
// 報錯
// uncaught typeerror: fun is not a constructor
箭頭函式只有乙個表示式時可以把{}return省略掉
let
fun=()
=>
'你好'
let f =
fun(
)console.
log(f)
二、箭頭函式不繫結arguments,取而代之需要用展開運算子解決…解決let
sum=
(...arguments)
=>
sum(1,
2,3,
4)
普通函式的argumentsfunction
fun(
)fun(1
,2,3
,4,5
)
三, 箭頭函式的this,始終指向父級上下文(箭頭函式的this取決於定義位置父級的上下文,跟使用位置沒關係,普通函式this指向呼叫的那個物件)var a =
200let obj =
, f:()
=>
} obj.fn(
)// 300
obj.f(
)//200
let obj2 =
, c:
function
(n)return f.
call
(m, n)}}
console.
log(obj2.b(
1))// 11
console.
log(obj2.c(
1))//11
五,箭頭函式沒有原型屬性vara=
()=>
functionb(
)console.
log(a.prototype)
;// undefined
console.
log(b.prototype)
;// constructor
箭頭函式與普通函式區別
1 箭頭函式是匿名函式,不能作為建構函式,不能使用new 2 箭頭函式不繫結arguments,取而代之用rest引數 解決 3 this的作用域不同,箭頭函式不繫結this,會捕獲函式定義的上下文中的this值,作為自己的this值,且一直不變 4 箭頭函式沒有原型物件 5 箭頭函式不能當作gen...
箭頭函式 普通函式
箭頭函式的語法比普通函式更簡潔,是乙個匿名函式,不能作為建構函式,且不能使用new 普通函式 letfun 普通函式 function fun 箭頭函式有兩種格式 一種是和return 另一種是把二者省略掉 1 1.不能使用newlet fun let fn newfun 1.function on...
箭頭函式與普通函式的區別
箭頭函式和普通函式的區別 首先就是 箭頭函式作為匿名函式,是不能作為建構函式的 再者就是更重要的一點 箭頭函式的特點就是不繫結this和arguments 舉個例子 settimeout function 3000 以上是乙個延時定時器中的普通function 我們都知道定時器中會改變this的指向...