Files
ClassContent/历届学生/fontendsix/每日课程/2021-10-29/function.html
2024-09-27 02:06:13 +08:00

95 lines
1.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>function 函数(方法)</title>
</head>
<body>
</body>
<script>
// function 就是具有相同功能代码的封装,降低代码冗余
// 定义 ?
// function 方法名( 可选 方法参数1,方法参数2,....) {
// // 你的代码
// }
// 没写名字的方法叫 匿名方法
// function test (money, clothes) {
// var b = 2, c = money;
// return `同学帮我洗: ${clothes}, 还剩余${c-b}元,还给了我`;
// }
// var test = function (money, clothes) {
// var b = 2, c = money;
// return `同学帮我洗: ${clothes}, 还剩余${c - b}元,还给了我`;
// }
// var c = test;
// console.log( c(10, "衣服") );
// var d = test(10, "衣服");
// console.log(d);
// 回调函数 在 异步 (同步) 代码里面用
// function async(callback) {
// var b = 1;
// setTimeout(function() {
// b = 3;
// callback(b)
// }, 3000)
// }
// async( function(ddd) {
// console.log(ddd);
// } )
// function a (callback) {
// var c = 1;
// callback(c)
// }
// a( function(res) {
// console.log(res);
// } )
// function forEach(data, callback) {
// for (let index = 0; index < data.length; index++) {
// callback(data[index], index, data)
// }
// }
// forEach(["哈哈1","哈哈2","哈哈3"], function(v,i,arr) {
// console.log(arr);
// } )
// 方法的作用域
// 全局作用域
// 局部作用域
// 变量提升
// var c = 1
// function a () {
// var c = 2;
// console.log(c); // 3
// }
// a();
// console.log(c); // 1
</script>
</html>