473,394 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 5152
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: MK | last post by:
What would be the best platform-independent way to refer to the current (execute) path for a Python script? self.dirname = ??? This variable should contain directory name for the current path....
1
by: 5tein | last post by:
I mean, with XSL functions such as SELECT can I only refer to XML element values or can I somehow also refer to XML attribute values? Is there any way to refer to XML content based on attribute...
7
by: Ivo | last post by:
How do I make the magic 'this' variable refer to an object of my choice, in a string of code which is to be eval'ed? Say, I have an object, an array with four elements: var myobject = ; and a...
2
by: ProRodman | last post by:
Dear all, I know that "me" can be used to refer current active form. How can I refer an object (e.g. a button) within it's own event code without using the object name (something just like...
7
by: Ryan | last post by:
I'm wanting to find the value of TableID on the current record displayed on my form. I cannot seem to find any method within the TableAdapter class to find this. An example I've found MS uses a...
6
by: Savante | last post by:
I have been writing a datalogging application. It reads in double's into a database. I want to be able to click on a row in a database (holds name of variable and also current value of variable)...
4
by: Mike | last post by:
I want to do something like the following (let's pretend that this is in file 'driver.py'): #!/bin/env python import sys def foo(): print 'foo'
8
by: Andy B | last post by:
Is there a way to refer to things in Session object without calling Session itself?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.