By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,678 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

How to refer to current object

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.