I am pondering on the following Javascript best practice pattern. I have a function in my code that has some nested functions. which of the following patterns should be preferred and why?
function parent() {
function child1() {
//child 1 code
}
function child2() {
//child2 code
}
//parent code
return {
child1: child1,
child2: child2
};
}
or
function parent() {
var child1 = function () {
//child 1 code
};
var child2 = function () {
//child2 code
};
//parent code
return {
child1: child1,
child2: child2
};
}