zoukankan      html  css  js  c++  java
  • JS总结

    一: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>
  • 相关阅读:
    触发器和存储过程简述
    sql笔记
    AES加密解密代码
    动态获取实体类及类中方法
    springboot metrics elk
    深入浅出Spring Security
    RandomValueStringGenerator
    ExceptionUtils
    spring.main.web-application-type: none
    excel前80%平均分
  • 原文地址:https://www.cnblogs.com/FJuly/p/4721807.html
Copyright © 2011-2022 走看看