Reputation: 79
A public method wants to call a private method (passing some objects as arguments) after some period of time... How do we do it?
Wanted something like this:
var someClass = function(someObj) {
var myPrivateMethod = function(someParam) {
alert('i got ' + someObj + '!');
if (someParam) alert('and i also got ' + someParam + '!');
}
var myDearPublicMethod = function(someParam) {
if (someParam) {
//call myPrivateMethod with setTimeOut so that it gets the someObj (and someParam if provided)
} else {
myPrivateMethod(someParam);
}
}
return {
somePublicMethod : myDearPublicMethod
}
}
someClass('something').somePublicMethod('somethingELSE');
Upvotes: 0
Views: 1486
Reputation:
it's not clear what is your goal
if (someParam) {
//call myPrivateMethod with setTimeOut so that it gets both someObj and someParam
} else {
myPrivateMethod(someParam);
}
why in the else branch you call a method with someParam as a parameter if in that branch you just verified that someParam is false, null or undefined? what the real difference between branches?
Upvotes: 0
Reputation: 700670
Call an anonymous function that calls the function:
window.setTimeout(function(){
localFunction(someObject);
}, 1000);
Upvotes: 2