473,747 Members | 2,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need more understanding of how to use the word "this"

I'm trying to gain a better understanding of javascript by studying
examples. I noticed this in an online tutorial. I don't get the use of
"this".
>>>>>>>>>>> >>>>>>>>>>>>>>> > You might want to add some event handler for an event to an element to
which there is already an event handler attached. That is possible by
storing the old event handler somewhere and then writing a new
function
which calls the old event handler.
For example suppose you have a document with buttons with onclick
handlers
<INPUT TYPE="button" NAME="aButton" VALUE="praise God"
ONCLICK="alert( 'Hail the Kibo');"

and you want add script that disables the event handler temporarily
then
you store the old event handler
var button = document.formNa me.aButton;
button.oldOnCli ck = button.onclick;
and write your new click handler which calls the oldOnClick when
necessary
function disabledButton (evt) {
if (this.disabled)
return false;
else
if (this.oldOnClic k)
this.oldOnClick (evt);
}
button.onclick = disabledButton;
Now you can set
button.disabled = false;
to disable the button and
button.disabled = true;
to enable it. Complete example:>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>

In the these two lines:

function disabledButton (evt) {
if (this.disabled)

Where did the "this" come from and what does it refer to? Also, where
did the property "disabled" come from???
Jul 23 '05 #1
1 1458
On 6 Nov 2004 09:57:16 -0800, lawrence <lk******@geoci ties.com> wrote:

[snip]
In the these two lines:

function disabledButton (evt) {
if (this.disabled)

Where did the "this" come from and what does it refer to?
This keyword, this, is an operator. It always references an object, though
which object depends upon context. In this case, it refers to the button.

When

button.onclick = disabledButton;

is executed, the onclick property of the object, button, refers to the
function, disabledButton. It becomes a method of that object. When you
click the button, disabledButton is called and because it is a member of
button, the this operator refers to that object.
Also, where did the property "disabled" come from???


Hopefully, it's now obvious: it is the disabled property of the button.

Does that help?

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1107
by: WJ | last post by:
What is "this" that is being used by many asp and asp.net web applications and is there "that" object some where ? Googled what is that and was not satisfied @ all ! I know for sure that in c#, I donot need "this" and the thing still works correctly as expected ! Is there a very good reason to use "this" notation on every line ? John
3
1388
by: Bill J | last post by:
For a VB.NET 2003 standard Windows MDI application, is there a way of implementing the "What's This" functionality through the applications main Help menu? All forms in the application have a HelpProvider. The forms do not have the 'HelpButton' property enabled because they are not dialogs. Thanks.
60
5053
by: Dave | last post by:
I'm never quite sure whether to use "this." or not when referring to fields or properties in the same class. It obviously works just fine without it but sometimes I wonder if using this. consistently may make the code easier to understand for someone else, etc. Using "this." makes it immediately clear, for example, that the variable being referred to is a member of the same class and is not declared in the method as a local variable. ...
19
7926
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache limiter - headers already sent in /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php on line 14
2
1549
by: Clemens Vasters | last post by:
"Is anybody from Microsoft reading this?" Well ... actually .... no .... welll ... maybe if you're really lucky. Let me explain ... My name is Clemens Vasters and I am a Program Manager on the Connected Framework team here at Microsoft. Our team owns ASP.NET Web Services, .NET Remoting, WSE, the Windows Workflow Foundation and the Windows Communication Foundation. We are deeply committed to help you with any problems you may have with...
3
1633
by: Jason S | last post by:
I have a rough understanding of what the "this" keyword refers to in Javascript but am not very clear on it. Is there a good reference that explains it well?
10
2739
by: Angel Tsankov | last post by:
Hello! Is the following code illformed or does it yield undefined behaviour: class a {}; class b {
14
2119
by: Alexander Dong Back Kim | last post by:
Dear all, I used to use C++ programming language at all time but moved to C# and Java. Few days ago, I restarted studying about C++ with a very beginner's mind. I wrote a simple class and gcc couldn't compile the class. Any hints that I'm missing? Header File: #ifndef __Calc_h__
5
10462
by: sunsande | last post by:
Hi there! Suppose you have N checkboxes on a MSAccess form and you want that every from them to show it's name on it's OnClick event. So you do: Private Sub checkbox1_Click() MsgBox checkbox1.Name End Sub In other programming languages I would write
0
8979
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9354
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9307
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6067
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4588
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2771
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.