Defining nested (sub) namespaces in JavaScript

by Jagadish Pulakhandam on 9/25/2012 4:08:46 PM
Rated 0 from 0 votes
Brief: Demonstrates on defining nested or sub namespaces in JavaScript and adding functions to it.
Posted to: Advanced JavaScript Programming/Development tutorials/videos- Object Oriented Programming
Add to DiggAdd to del.icio.usAdd to FURLAdd to RedditAdd to YahooAdd to BlinklistAdd to GoogleAdd to ma.gnoliaAdd to ShadowsAdd to Technorati

Attaches source code/video demonstrates the following:
  • How to define parent namespace in JavaScript
  • How to define child (nested or sub) namespace in JavaScript 
  • How to add functions to nested namespace
  • How to access or call or execute function in nested namespace
Source Code:

01.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
03.<html>
04.<head>
05.    <title></title>
06.    <script type="text/javascript">
07. 
08.        //DEMO: sub namespace (namespace inside another namespace)
09. 
10.        //encapsulating in a namespace
11.        var SampleLibrary = {};
12. 
13.        //add function to sub-namespace
14.        SampleLibrary.FirstLevelSub = {
15.            ShowMessage : function(msg) {
16.                alert(msg);
17.            }
18.        }
19. 
20.        SampleLibrary.FirstLevelSub.ShowMessage("another message");
21.    </script>
22.</head>
23.<body>
24. 
25.</body>
26.</html>


Join the .NET Code Central Community and join the discussion!
Signing-up is FREE and quick. Do it now, we want to hear your opinion
0

Rated 0 from 0 votes ( login  to rate)
DotnetKicks DotnetKicksDe DotNetShoutout

Attachments / Source Code
You need to Login or Join for FREE to download the following