Javascript - How do you call a function inside a class from within that class?

Viewed 114578

I am trying to call the function MyMethod from within a object but none of the syntax below works. There must be a really obvious error below but I can't see it.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

   <script type="text/jscript">

     function MyObject() {

       //how do I get one of these to work??
       this.MyMethod; //does not work
       this.MyMethod(); //does not work either
       MyMethod(); //does not work either

       this.MyMethod = function () {
         alert('It works');
       }
     }

     var test = new MyObject();

   </script>

</head>
<body>

</body>
</html>
5 Answers
Related