| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Document</title> |
| </head> |
| <body> |
| <script> |
| |
| |
| |
| let fn=function(){ |
| console.log("匿名函数赋值给变量,成为一个有名字的函数"); |
| } |
| fn(); |
| |
| |
| let obj={ |
| name:"小明", |
| say:function(){ |
| console.log(this.name+"说:hello"); |
| } |
| } |
| obj.say(); |
| |
| |
| document.onclick=function(){ |
| console.log("我被点击了"); |
| } |
| |
| |
| function add(a,b,callback){ |
| let result=a+b; |
| callback(result); |
| } |
| add(1,2,function(result){ |
| console.log("结果是:"+result); |
| }) |
| |
| function fn1(result){ |
| setTimeout(() => { |
| console.log("我是主函数,被调用了"); |
| result(); |
| }, 2000); |
| } |
| fn1(function(){ |
| console.log("我是回调函数,被调用了"); |
| }) |
| |
| |
| (function(){ |
| console.log("我是立即执行函数"); |
| }()); |
| |
| |
| let add1=(a,b)=>a+b; |
| console.log(add1(1,2)); |
| |
| |
| </script> |
| </body> |
| </html> |