函數function可以被認爲是Object的子類,也就是一個function對象可以擁有自己的變量和其它function對象當屬性。
<html>
<body>
<input type='button' id='btn1' value='按鈕1'/>
<input type='button' id='btn2' value='按鈕2'/>
<script type='text/javascript'>
function doClick(str){
if(str!=undefined)
alert(str);
else
alert('varible undefined');
}
document.getElementById('btn1').οnclick=doClick;
document.getElementById('btn2').οnclick=function(){
doClick('按鈕2');
}
</script>
</body>
</html>
以上這段代碼可以用來展示帶參數的 函數的調用情況,不過在firefox下,點擊btn1,alert的是“object MouseEvent",而在ie下點擊btn1,alert的是"varible undefined"。
似乎在firefox下面,如果調用的時候沒有指定參數,那麼就把鼠標事件當參數傳遞給函數。