Home > Web Front-end > JS Tutorial > Some summary of function declaration under javascript_javascript skills

Some summary of function declaration under javascript_javascript skills

WBOY
Release: 2016-05-16 19:06:56
Original
992 people have browsed it

function test(){
return 123;
}


Obviously this is a function declaration, what about the following
var b=function(){return 123};


Everyone is suspicious of this. It doesn’t seem to be a declaration, because the function has no name, it is just an anonymous function. Well, look again
var b=function test(){return 123};


Is this a function declaration? It seems so, then I will answer you "no"
alert(test);
var b=function test(){return 123};


You can test it on any js implementation other than IE, and an undefined test error will be reported. What if this is the case
var b=function test(){return 123};
alert( b);
alert(test);


will display the toString result of function test(){...}, but the second alert is still abnormal. Why? That is to say, function test(){return 123} here is not a statement, but a function object. The reference is just placed in b. Therefore, the function object is not bound to the test name by default like the declaration. Then why don't I call it Use ie to test, because
alert(test);
var b=function test(){return 123};


ie will display the function, ie is stupid, so It will distinguish between a separate function statement and the function object on the right side of =. In addition, IE even supports statements such as function String.prototype.test(){...}. It can be seen that IE's js has a lot of bugs. No wonder Wilson doesn't To support es4, we have to create es3.1, which is actually our own bug-fixed version.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template