Event triggering inside prototype

Posted by shivesh on Stack Overflow See other posts from Stack Overflow or by shivesh
Published on 2010-06-05T13:42:21Z Indexed on 2010/06/05 14:02 UTC
Read the original article Hit count: 163

Filed under:

When I try to call "Test" function I get an error.
How to fix that? (no jquery!)

Browser:firefox
error:

TypeError: this.Test is not a function

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>Untitled Document</title>
        <script type="text/javascript">



            MyClass = function(){
            }

            MyClass.prototype = {

                Init: function(){
                    var txt = document.getElementById("text");

                    if (txt.addEventListener) {
                        txt.addEventListener("keyup", this.Foo, true)
                    }


                },

                Foo: function(){
                    this.Test();
                },

                Test: function(){
                    alert('OK');
                }


            }
            window.onload = function(){
                obj = new MyClass;
                obj.Init();
            }
        </script>
    </head>
    <body>
    <textarea id="text" rows="10">
    </textarea>
    </div>
</body>

© Stack Overflow or respective owner

Related posts about JavaScript