As i understand when we invoke a method this contains reference to object which invoke this method. But what is an "object" and a "method" in the following case:
Consider html code snippet
<div id="parent">
<input type="submit" id="submit" value="submit" onclick="doThis(this)"/>
</div>
where doThis() is JS function, such that
doThis(obj){
obj.style.background="#ff00ff"
}
I know, that this will be contained reference to submit button, but i dont understand why.
-
What would you expect it to be?Raul Rene– Raul Rene2013年12月15日 19:09:32 +00:00Commented Dec 15, 2013 at 19:09
-
1Please stop using inline js. google.com/search?q=Why+is+inline+js+bad%3Fm59– m592013年12月15日 19:10:42 +00:00Commented Dec 15, 2013 at 19:10
-
1A great reference to learn basically everything about event handling: quirksmode.org/js/introevents.html.Felix Kling– Felix Kling2013年12月15日 19:24:34 +00:00Commented Dec 15, 2013 at 19:24
1 Answer 1
When an event handler content attribute is set
...
create a function object (as defined in ECMAScript edition 5 section 13.2 Creating Function Objects)
...
Set the corresponding event handler to the aforementioned function
and
Process the Event object
Eas follows:...
Invoke callback with one argument, the value of which is the Event object
E, with the callbackthisvalue set toE's currentTarget.