I am trying to figure out JavaScript namespaces... I would like to write couple of functions and secure them in namespaces like below.. but I think I don't get it very well..This is too simple question but it will be clear for me I guess If I see why that doesn't work..
Here an exp that I am trying:
var myApp = {
getTxt: function(x){
x.click(function(){
var txt = $(this).html();
alert(txt);
});
};
};
call myApp:
var box = $('.js-box');
alert(myApp.getTxt(box));
I think MyApp is created rightly but I am not sure about calling and firing the getTxt function..
Calling that:
myApp.getTxt(box)
doesn't mean to fire x.click function..? Why does it turn an object?
What am I doing wrong here? Thanx!