Adding a New Method to an Object - Javascript Language Basics

Javascript examples for Language Basics:Introduction

Description

Adding a New Method to an Object

Demo Code

ResultView the demo in separate window

<!DOCTYPE HTML>
<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <script type="text/javascript">
            var myData = {// w w w. j  av a  2s  .com
                name: "java2s.com",
                topic: "CSS",
            };

            myData.sayHello = function() {
              document.writeln("Hello");
            };

        </script>
    </body>
</html>

Related Tutorials