I am trying to learn object oriented javascript. Why is this call to an object method not working (no alert)?
When you click on the link, an alert is supposed to appear stating how old Bob is.
In case the link ever disappears, here is the HTML:
<a href="#" onclick="bob.say()">eh</a>
and here is my javascript.
function guy(person_name) {
this.name = person_name;
this.age = 32;
this.say = function() {
alert(this.name + " is " + this.age);
return false;
}
}
var bob = new guy("Bob");
Chrome Web Developer Console states
Uncaught ReferenceError: bob is not defined
However, I think I defined bob with var bob = new guy("Bob");.