切换导航
简历
工具
演示
查询
导航菜单
服务端
30
前端
114
数据库
82
进阶开发
8
桌面程序
2
QA
15
软件使用
36
规范协议
5
操作系统
11
AI
0
复用资源
6
硬件
0
标签
HTML
正则表达式
Json
包管理工具
vite
CSS
XPath
JavaScript
Jquery
less
ES6
Vue
React
vue 3
Layui
editor.md
sea.js
Zepto.js
mysql.js
mssql.js
NodeJs
Express
前端template
YAML
杂项
外部链接
.NET Core SDK和运行时安装包
淘宝 NPM 镜像
查询网
Tables Generator线上表格转换工具
引用cdn在线脚本和样式
首页
前端
JavaScript 头等函数
[TOC] ## 概述 **Q:**什么是头等函数 **A:**头等函数(Frist Class Function)是指在一些程序设计语言中,函数的地位被当作“头号公民”,例如 JavaScript ,函数可以和变量一样使用,函数可以当作参数传递,也可以当作另一个函数的返回结果,还可以将函数赋值给一个变量 > **将函数赋值给变量示例:** > ```JS var boo = function helloWorld(){ console.log("hello world") } boo(); // 变量调用 // 输出:hello world ``` > **将函数当作参数传递给另一个函数示例:** > + 常规传递 > ```JS function helloWorld() { return "hello world"; } function consoleInfo(fun, flag) { console.log(fun() + flag); } consoleInfo(helloWorld, ".") // 输出:hello world. ``` > + 带参的箭头函数 > ```JS function consoleInfo(fun, flag) { console.log(fun(flag)); } consoleInfo((txt) => { return "hello world" + txt; }, ".") // 输出:hello world. ``` > **将函数作为返回结果示例:** > + 使用双括号()()调用 >```JS function helloWorld(){ return function(){ console.log("hello world") } } helloWorld()(); // 输出:hello world ``` > + 使用变量调用 >```JS var helloWorld = function(){ return function(){ console.log("hello world") } } var consoleInfo = helloWorld(); consoleInfo(); // 输出:hello world ``` ***
扫一扫手机看
点击排行
windows 文件资源管理器使用
Layui 弹窗open使用说明
SQL Server 中字符串函数使用
C# 使用QQ邮箱代理做邮件接收功能
SQL Server关于apply的两种形式cross apply 和 outer apply
ASP.NET MVC 模型的自定义验证
nvm安装及常用命令
SQL Server 中数据类型转换
SQL Server 中WITH AS短语的使用
IE浏览器下AJAX缓存问题导致数据不更新的解决办法
订阅号