<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP ‘test3.jsp‘ starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script src="js/jquery-2.1.1.min.js"></script> <script> // function test(a,b){ // return a+b; // } // //alert(typeof test); //函数也是一种数据类型 function类型 // function test2(aa){ // aa(); // } // function test3(){ // alert(‘test3‘); // } // //test2(test3); //函数可以当做数据传入,还可以传入匿名函数 // test2(function(){ // alert(‘匿名函数‘); // }); // //在js函数中是可以嵌套的,避免这样使用 // function test4(){ // function test5(){ // alert(‘test5‘); // } // test5(); //test5的作用域是在test4内部,外部不能直接访问,在test4中调用 // } // //test4(); //js函数三种定义方式 //1.function语句式 function test(){ } //2.函数的直接量 var te=function test2(){ } //3.function构造函数式 var test3=new Function(‘a‘,‘b‘,‘return a+b‘); //alert(test3(1,2)); //解析顺序问题,对于function语句式的函数,javascript会优先解释 // test4(); function test4(){ alert(‘test4‘); } //alert(test()); //undefined //test(); //无作用,执行test()函数时,还没有执行到test5()函数处(只是有申明而已),所以未定义,表示申明了但是未赋值 var test=function test5(){ //alert(‘test5‘); } var t1=1; function t2(){ var t1=2; //function test(){return t1;} //2 //var test=function(){return t1;} //2 var test=new Function(‘return t1‘); //构造函数方式式,具有顶级作用域,和卸载外面一样,会输出1 alert(test()); } t2(); </script> </head> <body> This is my JSP page. <br> </body> </html>
本文出自 “matengbing” 博客,请务必保留此出处http://matengbing.blog.51cto.com/11395502/1878994
原文地址:http://matengbing.blog.51cto.com/11395502/1878994