箭头函数
let a = (aa, bb) => aa + bb
等价于
function a (aa,bb){
return aa+bb
}
自执行函数
只执行一次
(function () {
console.log(111111111);
})()
//回调函数:讲一个函数作为参数传入到另一个参数中执行
//高阶函数:参数为函数或者返回值为函数的函数成分为高阶函数
let a = function () {
console.log();
}
function test(b) {
b()
}
test(a)
递归调用
function calc(n) {
if (n === 1) return 1
let res = n + calc(n - 1)
return res
}
console.log(calc(20));
实现数组的分页
let arr = []
for (let i = 1; i < 102; i++) {
arr.push(i)
function getPageList(pageIndex, pageSize) {
console.log('共有' + Math.ceil(arr.length / pageSize) + '页');
let start = (pageIndex - 1) * pageSize //(页数-1)*每页的个数
let end = start + pageSize //(页数-1)*每页的个数+每页的个数
console.log(arr.slice(start, end));
}
console.log(getPageList(3, 6));
arguments.callee()//指向本函数,与函数名无关