I am trying to learn how to apply basic object oriented concepts to Javascript. Here, I just want to be able to create a class method, and then call the method from the outside when I click on the <input> element:
<html> <head> <script type="text/javascript"> var Foo = function() { } Foo.prototype.bar = function() { alert("blah"); } </script> </head> <body> <input type="submit" onclick = "Foo.bar()"> </body> </html>
This does not work. Firefox gives error Error: Foo.bar is not a function
However, if I call Foo() directly, and then from Foo I call this.bar() , it works fine. Why can't I call Foo.bar() from the outside?
source share