/    Sign up×
Community /Pin to ProfileBookmark

javascript function description

is it deference between function description like that
FunctionName = function(containerId,filename,varname){
bla bla}
and
function FunctionName(containerId,filename,varname)
{bla bla}

or it’s just a style?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@SparoHawkJun 14.2010 — The first method is called a lambda function too. You can read a bit abut it here with some examples:

http://stackoverflow.com/questions/16501/what-is-a-lambda-function#answer-16509
Copy linkTweet thisAlerts:
@rnd_meJun 15.2010 — [CODE][COLOR="Red"]FunctionName =[/COLOR] function [B]FunctionName [/B](containerId,filename,varname){
bla bla}
and
function FunctionName(containerId,filename,varname)
{bla bla}
[/CODE]


the red turns a function statement into a function expression. There are subtle differences. you can also name a function statement, as the bold text shows. The big practical diff is outside the function is the immediate and direct assignment to a var, rather than having the function name become a lexically scoped variable automatically .



you can use a function statement before it appears in source-order, but function expressions need to reached first, just like other vars.

also, function statements can be cached by the JS engine, whereas expression get re-eval'd each time they are reached.
×

Success!

Help @Rnt666 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...