I have a function which is return a object. in the object i have two function to show the popup and close it. it works within the parent function, but it’s not from out side.. is it not a right way to call that.. else how can i call the obj function from out side?
my function :
var popupHandler = function(handler,msg,popUp){
msg = msg == "help" ? "help" : "results"
$(handler).click(function(){
popObj.showPop(); //works
})
$('.cls-how2play').click(function(){
if(msg == 'help') popObj.closePop(); //works
});
var popObj = {
showPop : function(){
if(!(popUp).is(':visible')) $(popUp).fadeIn().children().find('.'+msg).show().siblings().hide();
},
closePop : function(){
$(popUp).fadeOut()
}
}
return popObj;
}
from calling ouside like this :
$('.ui-footer').click( function(){
var closeIt = popupHandler();
closeIt.popObj.closePop() }) //not works.. why?
}
any one can help me the right way to call the obj functions from outside of the returning function?
thanks.
As you are returning the
popObj, yourcloseIdwill get only the two functions, not wrapped in thepopObjobject. Therefor you will call the function like so, withoutpopObj: