A Nother variation, from @kuvos-i ' m not sureOf the performance//implications, if any, of the using the ' new ' keyword, but it works.//http://twitter.com/kuvos/status/182 09252090847232new function () {/* code */}new function () {/* code */} ()//only need parens if passing arguments2.What ' s wrong with "self-executing anonymous function?"Such a
JavaScript is an interpreted language, and function declarations are interpreted after the JavaScript code is loaded and executed, and the function expression is interpreted only when it executes to this line of code.There are two ways to define a
When the parser loads data into the execution environment, it does not discriminate between function declarations and function expressions. The parser is the first to read the function declaration and make it available (accessible) before executing any code. As for a function expre
hoisting, read and add the function declaration to the execution environment. When you evaluate the code, the JavaScript engine declares the functions for the first time and places them on the top of the source code tree. Therefore, even if the declared function code is behind the code that calls it, the JavaScript en
hoisting, read and add the function declaration to the execution environment. When you evaluate the code, the JavaScript engine declares the functions for the first time and places them on the top of the source code tree. Therefore, even if the declared function code is behind the code that calls it, the JavaScript en
list of this article is as follows:
How should we understand the working principle of the JavaScript engine?
JavaScript exploration: the importance of writing maintainable code
JavaScript exploration: exercise caution when using global variables
JavaScript exploration: var pre-parsing and side effects
");}();
Unfortunately, the preceding Writing Method reports a js syntax error.
Because when the Javascript parser parses the global function or function internal function keywords, the braces are parsed into function declarations by default, instead of
function declaration
function foo () {}
The function foo will be hoist (promoted) before the entire program executes, so it is available in the entire scope (scope) that defines the Foo function. It is fine even if you call it before the function definition.
the function can be invoked correctly. But this loosening is not conducive to rigorous coding, and in the long run it is likely to promote rather than prevent accidents from happening. After all, there is a reason why programmers arrange statements in a particular order.
Is there any other reason to support Function Expression?
You know what?
1
When you usually use JS to write functions, it is generally customary function fn () {} to declare a function, in reading some excellent plug-ins when you see the var fn = function () {} the creation of such functions, exactly what they What is the difference between using it, today in the spirit of breaking the sand pot to ask the end, well say this fascinating-
Copy Code code as follows:
function Checkmobile () {
var smobile = Document.mobileform.mobile.value
if (!) ( /^1[3|4|5|8][0-9]\d{4,8}$/.test (Smobile))) {
Alert ("Not a full 11-digit cell phone number or the correct number of the top seven");
Document.mobileform.mobile.focus ();
return false;
}
}
The following is the cloud Habitat Community editors on the above regular expression
expression.
var functionname=function (arg0,arg0,arg2) {
//function Body
}
This form looks like a regular variable assignment statement, which creates a function and assigns it to the variable functionname. The function created in this case is called an anonym
Using regular expressions to determine whether the Arabic numerals are 0-9
Copy Code code as follows:
function Regisdigit (fdata)
{
var reg = new RegExp ("^[0-9]$");
Return (Reg.test (fdata));
}
Use this expression to get the length of the string
Copy Code code as follows:
function Regdatalength (fdata)
{
var va
definition of function expression in 1.js
expression, a phrase in JavaScript that JavaScript computes (evaluate) a result. A constant in a program is the simplest expression. The variable name is also a simple
There are two ways to declare functions in javascript: function declarations and function expressions.
The difference is as follows:
1. Functions defined by the method declared by the function, the function name is required, and the fu
1) function declaration (functions Declaration); function declaration functions fundeclaration (type) { return type=== "Declaration"; } 2) function expression. function Expression var funexpression =
parser executes to the line of code it is in before it is actually interpreted.
In fact, the JS parser does not treat the function declaration and function expression equally. For function declarations, the JS parser will be read first, make sure that the declaration has been resolved before all the code executes, an
I remember interviewing Tencent interns when the interviewer asked me such a question.
Copy Code code as follows:
What is the difference between the two statements below?
function foo () {};
var bar = function foo () {};
Only two types of declarations were known. One is a function declaration, one is a
This article mainly introduces the relevant information about function expression closures in javascript BASICS (6). For more information, see the reasons why javascript supports function closures. The stored data here is only the value of the variable in the
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.