HTML代码:
<button id="button1">点击弹出结果1</button>
<button id="button2">点击弹出结果2</button>
<button id="button3">点击弹出结果3</button>
JS代码:
var animal = 'dog';
function getAnimal(adjective) { alert(adjective+' '+this.animal); }
var myObj = {animal: 'camel'};
document.getElementById("button1").onclick = function() {
getAnimal('lovely');
};
document.getElementById("button2").onclick = function() {
getAnimal.call(myObj, 'lovely');
};
document.getElementById("button3").onclick = function() {
getAnimal.apply(myObj, ['lovely']);
};