B
blackholebutterfly
I have seen a couple of ways to define private functions inside other
functions.
1.
var myFunc1 = function() {
function myInnerFunc() {
}
};
2.
var myFunc2 = function() {
var myInnerFunc = function () {
};
};
Let's assume that both myFunc1 and myFunc2 have a "public" method also
that calls the "private" method:
this.init = function() {
myInnerFunc
};
Is there any reason to write/define the private methods one way as
opposed to the other? I am leaning toward using the 2nd way (using var
myInnerFunc = ...) but I cannot give a good reason for choosing this
way instead of the way in #1 above. (I realize that the -- this --
keyword is unavailable in the private method using either construct.)
As always, many thanks.
b l a c k h o l e b u t t e r f l y
functions.
1.
var myFunc1 = function() {
function myInnerFunc() {
}
};
2.
var myFunc2 = function() {
var myInnerFunc = function () {
};
};
Let's assume that both myFunc1 and myFunc2 have a "public" method also
that calls the "private" method:
this.init = function() {
myInnerFunc
};
Is there any reason to write/define the private methods one way as
opposed to the other? I am leaning toward using the 2nd way (using var
myInnerFunc = ...) but I cannot give a good reason for choosing this
way instead of the way in #1 above. (I realize that the -- this --
keyword is unavailable in the private method using either construct.)
As always, many thanks.
b l a c k h o l e b u t t e r f l y