470,613 Members | 1,571 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,613 developers. It's quick & easy.

How to refer to current object

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?
Oct 29 '06 #1
1 5034
Kai Zhu wrote:
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
Oct 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Ivo | last post: by
2 posts views Thread by ProRodman | last post: by
4 posts views Thread by Mike | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.