A common method of creating private methods (of sorts) in javascript is this:
Class = function (arg0, arg1) {
var private_member = 0;
var privateMethod = function () {
return private_member;
};
}
The above example could also have been done with a function declaration instead of a function expression:
Class = function (arg0, arg1) {
var private_member = 0;
function privateMethod () {
return private_member;
}
}
In what ways are these two ways of declaring a private method different? (Outside of one being an expression and the other being a declaration)
For example, the expression obviously generates a new function everytime the constructor gets called. Does this happen with the function declaration aswell, or does it only get evaluated once because function declarations are evaluated at parse time? (As opposed to function expressions which are evaluated at execution time, you get the idea.)
EDIT: I'm aware that javascript doesn't really have private methods. I'm using the the term loosely.
EDIT: Not a duplicate of var functionName = function() {} vs function functionName() {}, if anything a duplicate of function expression vs function declaration with regard to javascript 'classes'. My question isn't about the difference between function expressions and function declarations in general, but their differences specifically in regards to "private members" in javascript "classes".