Forum Moderators: open
var myDiv = getElementById( "divToMove");myDiv.mover = new myMovingClass();
myDiv.mover.moveTo( x, y);
I don't even know if that's feasible or possible. The object in assigning a class to an element, is so I don't have to keep track of each element within the mover class. This way the entire class would be duplicated for each element, in it's own namespace.
When I've had this situation in the past I've always used an associative array of the element ID's to track things, but this way would be more efficient.
Is it possible?
-Geoffrey Lee
myFunc.prototype.doSomething=function(){
with(this) alert(param1+" on first, "+param2+" on second, "+param3+" on third");
}
myFunc.prototype.doSomethingElse=function(){
with(this) document.write(param1+" on first, "+param2+" on second, "+param3+" on third");
}
var myVar = new myFunc("who's","what's","I don't know's");
myVar.doSomething();
myVar.doSomethingElse();
I have lots of JS piling up, and I want to prevent duplicate function/variable names.
I think may be you are refering to object literal notation and creating a global namespace...?
[webmasterworld.com...]
Another of Fotiman's code examples...
[webmasterworld.com...]
So working on that theory, with my original code....
myDiv.mover = new myMovingClass();
myDiv.mover.moveTo( x, y);
My myMovingClass could use this.onClick to make itself move, but then how does the moveTo function know which element it's on, wouldn't "this" refer to mover?