南阳seo网站排名优化,wordpress 关联微信,定制软件开发报价,网页浏览器软件有哪些题记 函数和匿名函数的简单用法
定义函数
定义普通函数 function 函数名(参数) { // 函数体 } 定义参数为函数的函数 可以先定义一个函数#xff0c;然后传递#xff0c;也可以在传递参数的地方直接定义函数 function say(word) { console.log(word); } function execut…题记 函数和匿名函数的简单用法
定义函数
定义普通函数 function 函数名(参数) { // 函数体 } 定义参数为函数的函数 可以先定义一个函数然后传递也可以在传递参数的地方直接定义函数 function say(word) { console.log(word); } function execute(someFunction, value) { someFunction(value); } execute(say, Hello); 定义匿名函数 直接把函数写在参数的位置不用给函数写名字 function execute(someFunction, value) { someFunction(value); } execute(function(word){ console.log(word) }, Hello); 创建HTTP服务器 使用匿名函数的形式 var http require(http); http.createServer(function(request, response) { response.writeHead(200, {Content-Type: text/plain}); response.write(Hello World); response.end(); }).listen(8888); 使用普通函数的形式 var http require(http); function onRequest(request, response) { response.writeHead(200, {Content-Type: text/plain}); response.write(Hello World); response.end(); } http.createServer(onRequest).listen(8888); 后记 觉得有用可以点赞或收藏