Reputation: 5745
I have the following methods.. I'd like to be able to mock something up so I can test whether or not pete() has been called. Not sure how to do this when im using closures. Any ideas ?
bla = (function(){
var a = 0;
jim = function(){
if(a==1){
pete();
}
},
pete = function(){
return 1;
}
var publicInterface = {
"publicjim": jim
}
return publicInterface;
})();
Upvotes: 1
Views: 1645
Reputation: 236122
In your self-executing anonymous function, you're using object propertys.
jim
and pete
need to be local variables in order to "hide" them via closure.
var bla = (function(){
var a = 1;
var jim = function() {
if (a == 1) {
pete();
}
};
var pete = function() {
return 1;
};
return {
"publicjim": jim
};
})();
Upvotes: 3