B
barry_normal
Hello everyone,
I'm trying to get my head round the javascript event model at the
moment and just don't seem able to do what I want. Any help would be
greatly appreciated, I'm hoping it's an obvious problem...
So here's what I'm trying to do.
I have an object which creates a menu on the page, it looks a bit like
this:
function CatList(){
this.myWorkspace = new Workspace();
....
//THEN CatList CREATES SOME MENUS AND ADDS THEM TO THE DOCUMENT
var tl_menu = document.createElement('li');
tl_menu.thingy = tls.childNodes[1].firstChild.nodeValue;
//THEN I ADD EVENT LISENERS
tl_menu.addEventListener("mouseup", handlemouse, false);
}
//HANDLER METHOD
handlemouse function(){
var NAME_VALUE = this.thingy;
}
//I want to be able to call a function on this.myWorkspace and pass it
the value NAME_VALUE but I just can't work out how to do it! By the
time you get to the handler 'this' refers to the element which
triggered the mouse event.
You can use this.myWorkspace.createOtherStuff() as the handler but
then you can't pass in a value. Seems like catch 22.
Any insights would be wonderful. I've been plugging away at this for
what seems like hours.
All the best
BN
I'm trying to get my head round the javascript event model at the
moment and just don't seem able to do what I want. Any help would be
greatly appreciated, I'm hoping it's an obvious problem...
So here's what I'm trying to do.
I have an object which creates a menu on the page, it looks a bit like
this:
function CatList(){
this.myWorkspace = new Workspace();
....
//THEN CatList CREATES SOME MENUS AND ADDS THEM TO THE DOCUMENT
var tl_menu = document.createElement('li');
tl_menu.thingy = tls.childNodes[1].firstChild.nodeValue;
//THEN I ADD EVENT LISENERS
tl_menu.addEventListener("mouseup", handlemouse, false);
}
//HANDLER METHOD
handlemouse function(){
var NAME_VALUE = this.thingy;
}
//I want to be able to call a function on this.myWorkspace and pass it
the value NAME_VALUE but I just can't work out how to do it! By the
time you get to the handler 'this' refers to the element which
triggered the mouse event.
You can use this.myWorkspace.createOtherStuff() as the handler but
then you can't pass in a value. Seems like catch 22.
Any insights would be wonderful. I've been plugging away at this for
what seems like hours.
All the best
BN