- 箭頭函數(shù)的不適用場景
箭頭函數(shù)不能使用 arguments陋葡、super 和new.target雹姊,也不能用作構(gòu)造函數(shù)颖榜。此外,箭頭函數(shù)也沒有 prototype 屬性
- 函數(shù)名的擴展
let test1 = function(){
cosnole.log(" this is test1 function")
}
test1() // ====> "this is test1 function"
let newTest = test1
test1 = null
newTest() // "this is test1 function"
test1() // not a function
說明:因為函數(shù)名就是指向函數(shù)的指針独悴,所以它們跟其他包含對象指針的變量具有相同的行為扇谣。這意味著
一個函數(shù)可以有多個名稱
- 函數(shù)傳參的知識點
有個需求,需要一些傳參數(shù)牲平,但是堤框,參數(shù)具體有多少個是不知道的。那這種情況需要如何解決呢纵柿?其實胰锌,每個函數(shù)里都會有 arguments 對象。我們可以從這個對象可以知道傳入的參數(shù)個數(shù)了
let a = '參數(shù)1'
let b = '參數(shù)2'
let c = '參數(shù)3'
let d = '參數(shù)4'
function test(a,b,c,d){
console.log(arguments.length) // 4
console.log(arguments[0]) // '參數(shù)1'
console.log(arguments[1]) // 參數(shù)2
....
}