A function is a very important language element in JavaScript, and provides a function keyword and built-in object function, following its possible usage and relationships between them.function how to usevar function ()//or function foo01 () {
Scenario One:
The code is as follows
Copy Code
var yx01 = new function () {return "center"};alert (YX01);
We run the story one code, and it returns "[Object Object]", which is equivalent to:
The
A function is a very important language element in JavaScript and provides a function keyword and a built-in object function, and the following are the possible uses and relationships between them.
Use method One:
Copy Code code as follows:
A function is a very important language element in JavaScript and provides a function keyword and a built-in object function. The following describes its possible usage and the relationship between them.
Method 1: VaR Foo01 = Function () //
A function is a very important language element in JavaScript, and provides a function keyword and built-in object function, following its possible usage and relationships between them.Use method One:VarFoo01=function()//or Fun01 = function () {var
No more nonsense, directly on the test code
Copy Code code as follows:
var aa = "{name: ' Cola ', item:[{age:11},{age:22},{age:23},{age:23}]}";
var now = new Date (). GetTime ();
for (var i = 0; i var a = eval ("+ AA +");
}
The function is a very important language element in JavaScript, providing a function keyword and a built-in object function, and the following are the possible uses and relationships between them. Use method one : Var foo01 = function ()
http://www.jb51.net/article/7955.htm
A function is a very important language element in JavaScript and provides a function keyword and a built-in object function, and the following are the possible uses and relationships between them.Use method One:
The eval () method is not available for random use, and using the eval () method when it is not appropriate may cause the entire program to be problematic;and the new function () is not that big a problem. Although the new function () in any case,
The code is as follows
Copy Code
Varyx01=new function () {Return "center"};alert (yx01);//[objectobject]
Equivalent:
The code is as follows
Copy Code
function Anonymous class () {return "center";
When you have to execute a string as code, many people first think of using eval, but in fact, using the new function is more secure. Why is it safe? Look at an example. eval can affect the current scope and all the variables of the parent scope,
2015-9-15 16:26:05I've seen this code these days:var tojson=function(A) { try { ////run return in the body (return a); return a. return (new Function ("return" + A )) (); Catch (
Use the new Function () for syntax checking
The eval () method is not available for random use, and using the eval () method when it is not appropriate may cause the entire program to be problematic;
and the new Function () is not that big a problem.
Code:
Copy Code code as follows:
Friendly reminder: For your fingers to be safe, please run it under Chrome
' Alert (' Hello ') '. Replace (/.+/, eval);
' Alert (' Hello ') '. Replace (/.+/, function (m) {new function (m) ();});
var i
Test One:var fud01 = function (){var temp = 100;This.temp = 200;return temp + this.temp;}Alert (typeof (FUD01));Alert (FUD01 ());Operation Result:Function 300The most common way to use function is to set a JavaScript function. In a variable scope
Most of us have used JavaScript. In recent years, JavaScript has become more magical and easy with the popularity of various JavaScript frameworks. "Anonymous (Anonymous) function? I don't know what it is, but it looks similar to what I wrote ."You
Reprinted from: http://blog.snsgou.com/post-13.htmlIn JS, the JSON string is parsed into a JSON data format, typically in two ways:1. One for using the eval () function.2. Use the function object for return parsing.The first parsing method: Use the
has been to function () smattering, today on the use of function () to do a summaryThe function is actually a fully functional object, and the function is created directly with Fucntion ().Syntax rules:var function name = new function (arg1, arg2,
Use new Function () for syntax check
The eval () method cannot be used in disorder. Using the eval () method when not appropriate may cause problems in the entire program;
And new Function () is not that big a problem. Although the new Function ()
Most of us have used JavaScript, and in recent years the popularity of JavaScript frameworks has made JavaScript more magical and easy. "Anonymous (anonymous) function?" I don't know what it is, but it seems to be the same as what I wrote. ”You may
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.