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 temp = + ; this. Temp = $ ; return temp + this . temp; } alert (typeof(foo01)); Alert (foo01 ());
Operation Result:
function
The most common way to use function is to set a JavaScript function. The two kinds of writing show that the effect is exactly the same, but the only one is that the latter is a higher initialization priority. In a variable scope within a large expansion number, this refers to the owner of the Foo01, the Window object.
Use Method Two:
VarFoo02=Newfunction() {var temp = 100 this.temp = 200 return temp + this.TEMP; } alert ( foo02); alert ( Foo02.constructor ());
Operation Result:
Object
This is a comparison of the use of puzzle functions, as if a function is set. But this is actually a user-defined object in JavaScript, but this is an anonymous class. This usage is basically not related to the use of the function itself, and a variable scope is constructed in the large expansion number, which refers to the scope itself.
Use method Three:
VarFoo3=NewFunction ('var temp = + ; this. Temp = $ ; return temp + This . temp; '); Alert (typeof(Foo3)); Alert (Foo3 ());
Operation Result:
function
Use the system built-in function object to build a function, and the first way in method one is exactly the same on both the effect and the initialization priority, that is, the function body is given as a string.
Use method Four:
VarFoo4= function (' typeof
Operation Result:
function
This method is not used frequently, the effect and method are the same, but it is unclear whether new to generate any side effects, this also embodies the JavaScript one of the biggest features: Flexible! Can save on the province.
function, new function, new function