I want to setup nested namespaces to organize my code. I am trying to follow the plugin-like structure described in this article. The problem is I don't understand how to access this.error_msg
in my example. Have I set this up correctly? Would I have to use jQuery .extend
or .prototype
to access this.error_msg
?
(function(TC, $, undefined){
TC.ajax = function() {
this.error_msg = 'default error...';
};
TC.ajax.run = function(){
//do stuff...
TC.ajax.handle_error();
};
TC.ajax.handle_error = function(){
alert(this.error_msg);
};
}(window.TC = window.TC || {}, jQuery));
// Test it
TC.ajax.run();