您的位置:首页 > Web前端 > JavaScript

JScript 中 eval 实现 VBScript ExecuteGlobal 功能, 函数 fExecuteGlobal by shawl.qiu

2007-09-09 11:41 741 查看

JScript 中 eval 实现 VBScript ExecuteGlobal 功能, 函数 fExecuteGlobal by shawl.qiu

说明:
顾名思义,  ExecuteGlobal 就是把局部变量弄成全局变量...

虽然实现函数只是短短几行...
不过这几行中包含的原理实在是太多了, 俺不想费劲解释... 请自行消化.

shawl.qiu
2007-09-09
http://blog.csdn.net/btbtd

内容:
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
</head>
<body>
<%  

 fTest("j");
 
 Response.Write("i: "+i+"<br/>");
 Response.Write(typeof(i)+"<hr/>");
 
 Response.Write("f: <xmp>"+f+"</xmp><br/>");
 Response.Write("Global: "+typeof(f)+"<br/>");
 
 Response.Write("j: <xmp>"+j+"</xmp><br/>");
 Response.Write("Global: "+typeof(j)+"<br/>");
 
 function fTest(DynArg)
 {
  var i=0;
  
  fExecuteGlobal("f", f);
  fExecuteGlobal("i", i);
  
  if(DynArg) fExecuteGlobal(DynArg, eval(DynArg));
  
  function j()
  {
   Response.Write("j saying hi.<br/>");
  }
  
  function f()
  {
   Response.Write("f saying hi.<br/>");
  }
 }
 
 function fExecuteGlobal(sVar, Var)
 { // shawl.qiu code, void return
  if(!sVar) throw new Error("var name must be not empty!");
  eval(sVar+"=Var");
 } // function fExecuteGlobal(sVar, Var)
%>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息