javascript中json、回调函数、匿名函数的一些测试


<html>
	<body>
		<input type="button" name="name" value="xxxx" οnclick="test()"/>
	</body>
	<script language="javascript">
		var person = {name:"张三",sex:"男",age:"13",address:[{p:"粤",c:"深",s:"南京路"},{p:"湘",c:"长",s:"西御街"}],testclick:function(){alert("hello world!")}};
		function student(){alert("student");}
		person.student =student;
		
		//匿名函数
		(function(x){//x是形参
			function a(){//a是私有方法,如果不赋值到外部可见的变量上,外部将不能调用a
				return {
					b:b,
					c:x+"x"
				}
			}
			function b(){
				alert("b");
			}
			person.a = a;//把a添加到person上,让外部可以调用a
		})("a");//实参 
		
		//回调函数
		function func(a,b,callback){
			var num = a-b;
			callback(num);
		}
		
		function test(){
			alert(person.age);//13
			alert(person.address[1].c);//长
			alert(person.testclick);//function(){alert("hello world!")}
			var t = person.testclick;
			t();//hello world!
			person.student();//student
			var t1 = person.a();
			t1.b();//b
			alert(t1.c);//ax
			func(8,2,function(num){
				alert(num);//6
			});
		}
	</script>
</html>


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值