码迷,mamicode.com
首页 > Web开发 > 详细

JS总结

时间:2015-08-11 20:52:11      阅读:135      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!