The below example shows how to create namespaces with javascript.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> //run the init function on document ready $(document).ready(function() { myprogram.init(); }); //root namespace var myprogram = { //define the children namespaces init : function() { //onloads myprogram.load.user(101); myprogram.load.detail(999); }, load : { //define load's child namespaces user : function(id) { alert(id); }, detail : function(id) { alert(id); } }, save : function(vars) { alert('You just saved '+vars); }, delete : function(vars) { if (myprogram.confirm('Are you sure you want to delete?')) { alert('You just deleted '+vars); } }, confirm : function(msg) { var agree = confirm(msg); if (agree) return true; } }; </script>
Below is an example of how the javascript namespace would be used in a link.
<a href="#" onclick="myprogram.save('John Doe'); return false;">Save John Doe</a><br /> <a href="#" onclick="myprogram.delete('John Doe'); return false;">Delete John Doe</a><br />