zoukankan      html  css  js  c++  java
  • javascript中的回调函数

    <!DOCTYPE html>
    <html>
    
    	<head>
    		<meta charset="UTF-8">
    		<title>回调函数使用</title>
    	</head>
    
    	<body>
    		<!--一。基本用法-->
    		<script language="javascript" type="text/javascript">
    			//回调函数基本用法:
    			//		function dosomeThing(callback){
    			//			callback("我是","回调",'函数');
    			//		};
    			//		function foo(a,b,c){
    			//			alert(a+b+c);
    			//		};
    			//		dosomeThing(foo);
    
    			//匿名函数中使用回调函数:
    			//			function dosomeThing(domsg, callback) {
    			//				alert(domsg);
    			//				if(typeof callback == "function") {
    			//					callback("回调函数中的","参数");
    			//				};
    			//			};
    			//			dosomeThing("匿名函数", function(a,b) {
    			//				alert("此处是匿名函数中使用回调函数;"+a+b);
    			//				
    			//			});
    		</script>
    
    		<!--二。高级用法-->
    		<!--<script language="javascript" type="text/javascript">
    			function Thing(name) {
    				this.name = name;
    			};
    						Thing.prototype.doSomething = function(callback) {
    							callback.call(this);
    						};
    			function foo() {
    				console.log(this.name);
    			};
    			var t = new Thing("Joe");
    			t.doSomething(foo);
    		</script>-->
    		<!--传参数-->
    		<!--<script type="text/javascript">
    			function Thing(name){
    				this.name=name;
    			};
    			Thing.prototype.doSomething=function(callback,parameterss){
    				callback.call(this,parameterss);
    			};
    			function foo(parameterss){
    				console.log(parameterss+" "+ this.name);
    			};
    			var t=new Thing("Joe");
    			t.doSomething(foo,"Hi");
    		</script>-->
    		<!--使用 javascript 的 apply 传参数-->
    		<script type="text/javascript">
    			function Thing(name) {
    				this.name = name;
    			};
    			Thing.prototype.doSomething = function(callback) {
    				callback.apply(this, ['Hi', 3, 2, 1]);
    			};
    
    			function foo(parameterss, three, two, one) {
    				console.log(parameterss + " " + this.name + " " + three + two + " " + one); //输出:Hi Joe321
    			};
    			var t = new Thing("Joe");
    			t.doSomething(foo);
    		</script>
    	</body>
    
    </html>
    

      

  • 相关阅读:
    操作数据库pymysql
    深度学习-目标检测(Fast R-CNN)
    解释--全连接层输入大小固定
    深度学习-目标检测(IOU)
    深度学习-目标检测(SPPNet)
    深度学习-目标检测(R-CNN)
    机器学习-Whitening(白化)
    Win10 将slim加入PYTHONPYTH
    tensorboard 使用
    卷积神经网络--padding
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/7661527.html
Copyright © 2011-2022 走看看