Development| HTML| JavaScript| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JavaScript add namespace 
 

In the given example, we have created two objects Util and Coll.

 

JavaScript add namespace

                         

In this section, we are going to create the namespace using the JavaScript.

In the given example, we have created two objects Util and Coll. By creating the objects for each namespace, we can add the functions as methods to these objects. Here we have added the functions add() and sub() to the Util object. And the functions mul() and div() to the Coll object. By using Util.add(), Util.sub(), Coll.mul() and Coll.div(), we can call the methods globally on the page as we have done here

 

 

 

 

Here is the code:

<html>
<h2>Use of Namespaces</h2>
<script>
var Util = {
add: function() {
alert("This is addition method.");
},
sub: function() {
alert("This is subtraction method.");
}
}
var Coll = {
mul: function() {
alert("This is multiplication method.");
},
div: function() {
alert("This is division method.");
}
}
</script>
<input type="button" onClick="Util.add();" value='Add'>
<input type="button" onClick="Util.sub();" value='Subtract'>
<input type="button" onClick="Coll.mul();" value='Multiply'>
<input type="button" onClick="Coll.div();" value='Divide'>
</html>

Output will be displayed as:

On clicking the button, you will get the alert messages.

Download Source Code:

                         

» View all related tutorials
Related Tags: java javascript html c table ant script delete object method ip this oo tab if call footer with to e

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.