1

This link - http://javascript.crockford.com/private.html - says the following regarding private members in JavaScript:

Private

function Constructor(...) {
  var that = this;
  var membername = value;
  function membername(...) {...}
}

Note: The function statement

function membername(...) {...}

is shorthand for

var membername = function membername(...) {...};

I thought about this, and tried the following: Instead of

var membername = function membername(...) {...};

I did just

var membername = function(...) {...};

and it seems to have the same effect.

Can anyone verify that these two are exactly the same in all cases? Do they only have the same privacy level/scope when used inside a function? What if they are just in the top-level definition of a JS file?

Thanks.

dmonopoly
  • 2,905
  • 4
  • 30
  • 47
  • They are not the same. But the difference is pretty minor: the one of them has a name and last one doesn't. Check `membername.name` in both cases. – dfsq Dec 26 '14 at 16:50
  • 1
    @LucasTrzesniewski He's not asking about `function functionName`, he's asking about `var foo = function functionName`, which is different. – Barmar Dec 26 '14 at 16:54
  • @Barmar this case is described [in this answer](http://stackoverflow.com/a/338053/3764814) – Lucas Trzesniewski Dec 26 '14 at 16:55
  • This is a pretty good article about named function expressions: http://kangax.github.io/nfe/ . – Felix Kling Dec 26 '14 at 17:04

0 Answers0