函数和箭头函数

函数

一、 函数分类:
            1、有参数 有返回 var x=string.split(',');
            2、无参数 有返回 var x=string.trim();
            3、有参数 无返回 forEach(function(){})
            4、无参数 无返回 没有

二、 函数的返回值

返回值的作用:返回上级调用者

三、最大值和最小值

var x = [2, 5, 8, 9, 22, 3, 3, 44, 24, 545];
console.log(Math.max(...x));
console.log(Math.min(...x));

四、 

箭头函数 

一、 匿名函数:

1、立即执行;2、方法参数,事件回调

            (function() {
				console.log('立即执行匿名函数');
			})();
			~function() {
				console.log('立即执行匿名函数');
			}();
			!function() {
				console.log('立即执行匿名函数');
			}();

 二、点击

        document.body.onclick=function(){
				console.log('点击事件!!');
			}
			var x=[];
			x.forEach(function(){
				
			})

三、 箭头函数 是匿名函数的 间写

            (()=>console.log('箭头函数'))();
			(a=>console.log('a:',a))(5);
			((a,b)=>console.log('a:',a,'b',b))(5,7);
			var x=(()=>{return 'qiku';})();
			var x=(()=>'qiku')();
			console.log(x)

四、 数据

            var obj={
				name:'张三',
				birth:'2002-9-8 15:33:22',
				getAage:function(){
					console.log('外部函数的:',this.name);
					(()=>{
						console.log('内部函数的:',this.name);
					})();
				}
			}
			obj.getAage();

五、按钮事件

            document.querySelector('button').onclick=()=>{
				console.log('onclick:',this);
			}
			document.querySelector('button').onclick=function(){
				console.log('onclick:',this);
			}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值