Copy codeThe Code is as follows:
Eval. asp
<% @ LANGUAGE = 'javascript '%>
<Script Language = "javascript" runat = server>
Eval ("var f1 = 1, f2 = 2, f3 = 3 ;");
Response. Write (f1 + "<br/> ");
Response. Write (f2 + "<br/> ");
Response. Write (f3 + "<br/> ");
</Script>
Running result:
1
2
3
Eval01.aspx
<% @ LANGUAGE = 'javascript 'DEBUG = "true" %>
<Script Language = "javascript" runat = server>
Eval ("var f1 = 1, f2 = 2, f3 = 3 ;");
Response. Write (f1 + "<br/> ");
Response. Write (f2 + "<br/> ");
Response. Write (f3 + "<br/> ");
</Script>
The third line has a syntax error!
You can dynamically add attributes to an empty object to solve the problem of defining variables by table fields:
Table Name: T
F1 int,
F2 char (10 ),
F3 datetime
Asp:
Eval ("var F1 ='', F2 = '', F3 = '';");
Response. Write ("F1 =" + F1 );
Aspx:
Var T = {};
T ["F1"] = "";
T ["F2"] = "";
T ["F3"] = "";
Response. Write ("F1 =" + T. F1 );
<% @ LANGUAGE = 'jscript' DEBUG = "true" %>
<%
Var TAB = {
};
Var n = 12;
Var metadata;
For (var I = 0; I <n; I ++)
{
Limit = "F0" + (I <10 )? ("00") :( (I <100 )? ("0") :( ") + I;
TAB [topology] = I + 1000;
}
For (var I = 0; I <n; I ++)
{
Limit = "F0" + (I <10 )? ("00") :( (I <100 )? ("0") :( ") + I;
Response. Write (TAB [Response] + "<br/> ");
}
%>
Instructions on Jscript8.0 on the official Microsoft Website:
Http://msdn.microsoft.com/zh-cn/library/8e4z2w8w (v = vs.90). aspx # jsconupgradingapplicationcreatedinpreviusversionsofjscriptanchor7
Upgrade the application created in the previous JScript version
Visual Studio 2008
Other Versions
· Visual maxcompute 2010
· Visual maxcompute 2005
This topic has not been rated-rating this topic
Updated: February 1, November 2007
Most of the existing JScript code can well use the enhanced features contained in JScript 8.0, because for previous versions, JScript 8.0 is almost completely backward compatible. New Features of JScript 8.0 have created a new world.
By default, the JScript 8.0 program is compiled in quick mode. Because the quick mode has some restrictions on the allowed code types, the program may be more effective and run faster. However, some functions available in earlier versions are unavailable in quick mode. Most of these features are incompatible with multi-threaded applications and result in low code efficiency. For programs compiled using the command line compiler, you can disable the quick mode and use full backward compatibility. Note that the Code Compiled using this method runs slowly and has poor fault tolerance. The quick mode cannot be disabled in ASP. NET applications because of stability issues. For more information, see/fast.
Quick Mode
In quick mode, the following JScript behaviors are triggered:
· All variables must be declared.
· The function becomes a constant.
· Internal objects cannot have the expando attribute.
· Internal object attributes cannot be listed or changed.
· The arguments object is unavailable.
· You cannot assign values to read-only variables, fields, or methods.
· The eval method cannot define identifiers within a closed range.
· The eval method executes scripts in a restricted security context.
All variables must be declared
Explicit declaration of variables is not required in previous JScript versions. Although this feature allows programmers to reduce the number of keys, it also makes tracking errors difficult. For example, you may assign a variable name with a spelling error, which neither generates an error nor returns the expected result. In addition, undeclared variables have a global range and may cause other obfuscation.
Fast mode requires that declared variables be displayed. This helps avoid the various errors mentioned above and generate code that runs faster.
JScript. NET also supports type-Annotated variables. In this way, each variable is bound with a specific data type, and the variable can only store that type of data. Although the type annotation is not necessary, it helps avoid errors related to accidental storage of Error Data in variables and increase program execution speed.
For more information, see JScript variables and constants.
Function becomes constant
In previous JScript versions, functions declared using function statements are treated the same as variables that SAVE Function objects. In particular, any Function Identifier can be used as a variable to store any type of data.
In the fast mode, the function becomes a constant. Therefore, you cannot add new values or redefine a function. This avoids unexpected changes to the meaning of the function.
If your script needs to change the Function, you can explicitly use a variable to save the instance of the Function object. However, note that Function objects are slow. For more information, see Function objects.
Internal objects cannot have the expando attribute
In previous JScript versions, you can add the expando attribute to an internal object. For example, this behavior can be used to add a method for a String object to crop spaces before a String.
This is not allowed in quick mode. If your script uses this function, you must modify the script. You can define functions within the global scope, rather than attaching those functions as methods to objects. Then, rewrite each instance in the script (in this script, the expando method is called from the object) to pass the object to the appropriate function.
An important exception to this rule is the Global object, which can still have the expando attribute. All modifiers in the Global scope are actually attributes of the Global object. Obviously, the Global object must be dynamically scalable to support adding new Global variables.
Internal object attributes cannot be listed or changed
In previous JScript versions, you can delete, enumerate, or write predefined attributes of internal objects. For example, this behavior can be used to change the default toString method of the Date object.
This is not allowed in quick mode. Because internal objects cannot have the expando attribute, this function is no longer required, and the attributes of each object are listed in the reference section. For more information, see object.
The arguments object is unavailable.
The previous JScript version provides an arguments object in the function definition, which allows the function to accept any parameter. This parameter object can also reference the current function and call the function.
In quick mode, the arguments object is unavailable. However, JScript 8.0 allows function declaration to specify a parameter array in the function parameter list. This allows the function to accept any number of parameters, thus replacing some functions of the arguments object. For more information, see function statements.
In quick mode, there is no way to directly access or reference the current function or call the function.
You cannot assign values to read-only variables, fields, or methods.
In the previous JScript version, statements seem to assign values to read-only identifiers. This assignment will fail without prompting, and the only way to find that the assignment fails is to test whether the value has actually changed. Assigning a value to a read-only identifier is usually caused by an error because it does not have any effect.
In quick mode, if you try to assign a value to a read-only identifier, a compilation error is generated. You can either remove the value or try to assign values to non-read-only identifiers.
If the fast mode is disabled, the value assigned to the read-only identifier will fail without prompt at run time, but a warning will be generated during compilation.
The eval method cannot define an identifier within a closed range.
In previous JScript versions, functions and variables can be defined locally or globally by calling the eval method.
In quick mode, functions and variables can be defined in the call to the eval method, but they can only be accessed from this specific call. Once eval is completed, functions and variables defined in eval cannot be accessed again. The results calculated in eval can be assigned to any variables that can be accessed within the current range. Calling the eval method is slow. You should consider rewriting the code that contains these calls.
When the quick mode is disabled, the previous behavior of the eval method can be restored.
The eval method executes the script in a restricted security context.
In previous versions of JScript, the Code passed to the eval method will run in the same security context as the called code.
To protect users, the Code passed to the eval method is executed in the restricted security context unless the string "unsafe" is passed as the second parameter. Restricted security context prohibit access to system resources, such as file systems, networks, or user interfaces. If the code tries to access these resources, a security exception occurs.
When the second parameter of eval is the string "unsafe", the Code passed to the eval method is executed in the security context of the called code. In this way, the previous behavior of the eval method can be restored.
Security description:
When using eval in non-secure mode, only code strings obtained from known sources can be executed.