ment.getElementById(''thebutton''); the_button.onclick = deep_thought.ask_question; } window.onload = addhandler; //result [undefined] </script> ...
2.6
<button id=''thebutton'' onclick=''click_handler(this)''>Click me!</button> <script type="text/javascript"> function BigComputer(answer) { var self=this; self.the_answer = answer; self.ask_question = function () { alert(self.the_answer); } } function addhandler() { var deep_thought = new BigComputer(42), the_button = document.getElementById(''thebutton''); the_button.onclick = deep_thought.ask_question; } window.onload = addhandler; //result [42] </script> ...
2.7
<button id=''thebutton'' onclick=''click_handler(this)''>Click me!</button> <script type="text/javascript"> function btn_click(){ alert(this); } function addhandler() { the_button = document.getElementById(''thebutton''); the_button.onclick = btn_click; } window.onload = addhandler; //result [undefined] </script> ...
2.8
<button id=''thebutton'' onclick=''click_handler(this)''>Click me!</button> <script type="text/javascript"> function real_func() { alert(this); } function btn_click(){ setTimeout(real_func,100); } function addhandler() { the_button = document.getElementById(''thebutton''); the_button.onclick = btn_click; } window.onload = addhandler; //result [undefined] </script> ...
2.9
<button id=''thebutton'' onclick=''click_handler(this)''>Click me!</button> <script type="text/javascript"> Function.prototype.bind = function(obj) { var method = this, temp = functio |