I'm 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 externally when I click on an <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 doesn't work. Firefox gives the error Error: Foo.bar is not a function
However, if I call Foo() directly, and then from within Foo I call this.bar(), it works fine. Why am I unable to invoke Foo.bar() externally?