How to refer to current object

K

Kai Zhu

I've write a script like this.
<script>
function A() {
this.onMouseDown = function(event) {
.....
}
}
var objA = new A();
htmlelement.onmousedown = a.onmousedown;
</script>

But in the function onMouseDown, I want to refer to the object A itself. But
when I try "this" keyword,
I only get the htmlelement, but not objA. How can I refer to objA in the
onMouseDown function?
 
T

TheBagbournes

Kai said:
I've write a script like this.
<script>
function A() {
this.onMouseDown = function(event) {
.....
}
}
var objA = new A();
htmlelement.onmousedown = a.onmousedown;
</script>

But in the function onMouseDown, I want to refer to the object A itself. But
when I try "this" keyword,
I only get the htmlelement, but not objA. How can I refer to objA in the
onMouseDown function?

htmlelement.onmousedown = function(){A.call(htmlelement)};

Or, using the YUI toolkit ( http://developer.yahoo.com/yui/ )

YAHOO.util.Dom.addListener(htmlelement, "mousedown", A, true);

Note, this allows you to *add* listeners, not overwrite one handler.

Nige
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top