|
|
Posted on 12/15/2017 10:23:56 AM
|
|
|
|

In a JS program, sometimes when we want to get a variable value or an object's property, and the variable or object name may be dynamically generated, for example:
At this time, we need to use the eval method, and the code modification is as follows:
The detailed explanation of eval is as follows: The eval function takes a parameter s and returns s directly if s is not a string. Otherwise, the S statement is executed. If the result of the S statement execution is a value, it returns this value, otherwise it returns undefined. It should be noted that the object declaration syntax "{}" does not return a value, it needs to be enclosed in parentheses to return a value, a simple example is as follows
It can be seen that for object declaration statements, it is only execution and does not return a value. In order to return a commonly used object declaration statement such as "{}", it must be enclosed in parentheses to convert it to an expression in order to return its value. This is also one of the basic principles of using JSON for Ajax development. In the example, it can be clearly seen that the second alert statement outputs undefined, while the third output with parentheses is the object represented by the statement.
|
Previous:mysqldump imports and exports database summariesNext:AES, DES, MD5, RSA, SHA encryption interface
|