Hi
Ive been fiddling with trying to emulate classes in javascript - but currently getting an undefined error hen I click one of the vote buttons...
Ive got two vote buttons, 'vote_positive' and 'vote_negative' and have cretaed two vote button objects... on construction they firstly assign a value to the vote, then provide a 'method' which will ultimately be an ajax call, but for now is just an alert...
function vote_button(val){
this.value = val;
this.vote = function(){
alert(this.value);
};
}
function configure_voting(){
var voteUp = new vote_button(1);
var voteDown = new vote_button(-1);
$('vote_positive').onclick = voteUp.vote;
$('vote_negative').onclick = voteDown.vote;
}
function init(){
configure_voting();
}
window.onload = init;
Basically, the alert tries to access that objects 'value' variable... but for some reason it cant find it?!
Help!