Javascript examples for Language Basics:Introduction
You can add functions to an object too.
<!DOCTYPE HTML> <html> <head> <title>Example</title> </head> <body> <script type="text/javascript"> var myData = {// w w w . j a v a2 s. c om name: "java2s.com", topic: "CSS", printMessages: function() { document.writeln("Hello " + this.name + ". "); document.writeln("Today is " + this.topic + "."); } }; myData.printMessages(); </script> </body> </html>