Please, consider the following code.
<!DOCTYPE html>
<title>Question</title>
<script>
function report(handler, _this) {
alert(
"handler:
" + handler + "
" +
"this: " + _this + "
" +
"event: " + event + "
"
)
}
</script>
<input type=button id=A value=A onclick="report(A.onclick, this)">
<script>function f() {report(B.onclick, this)}</script>
<input type=button id=B value=B onclick="f()">
<input type=button id=C value=C>
<script>C.onclick = function () {report(C.onclick, this)}</script>
By clicking the buttons, I have seen that:
A.onclick
and B.onclick
are wrapped in "function
onclick(event) {...}".
- In
B.onclick
, this
is the window
(rather than a button).
Are there any other considerations?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…