首页 > Web开发 > 详细

JS总结

时间:2015-08-11 20:50:10      阅读:207      评论:0      收藏:0      [点我收藏+]
一:arguments.callee
<!DOCTYPE html>
<html>
<head>
	<script type="text/javascript">
	/*
	var facorial=function(num){
		if (num<1) {
			return 1;
		}else{
			return num*facorial(num-1);
		}
	}*/



	var facorial=function(num){
		if (num<1) {
			return 1;
		}else{
			return num*arguments.callee(num-1);//arguments.callee代表当前函数
		}
	} 

	var another=facorial;
	facorial=function(){
		return 1;
	}

	alert(facorial(5));
	alert(another(5));
	</script>
</head>
<body>
</body>
</html>

 

二:Prototype

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
	function Father(name,age){
		this.name=name;
		this.age=age;
	}

	Father.prototype.sayHi()=function(){
		alert("age+"+this.age+",name="+this.name);
	}

	//定义子类
	function Son(name,age,gender){
		this.gender=gender;
		Father.call(this,name.age);
	}

	Son.prototype=new Father();//这种写法是为了防止父类里面有子类的方法
	Son.prototype.fungame=function(){};

	var f1=new Father("F",29);
	f1.sayHi();

	var s1=new Son("S",true);

</script>
</head>
<body>

</body>
</html>

四:闭包

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
	function Closure(){
		var capturedVariable="capturedVariable";
		return function(){
			alert(capturedVariable);
		};
	}

	var closure=Closure();
	closure();
</script>
</head>
<body>

</body>
</html>

JS总结

原文:http://www.cnblogs.com/FJuly/p/4721807.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!