如何在JavaScript中執行函數覆蓋?JavaScript中的函數覆蓋
我有以下代碼。
function helloWorld() {
return 'helloworld ';
}
var origHelloWorld = window.helloWorld;
window.helloWorld = function() {
return 'helloworld2';
}
alert(helloWorld);
我想獲得像
helloworld helloworld2
輸出我該怎麼辦?
可能我描述的較少。其實我想打電話功能helloworld
,我想共同輸出這兩個功能。
呼叫從覆蓋原始和結果追加到返回值。 – DarthJDG
也可以在警報的參數中調用重寫。 – Teemu
你必須閱讀關於JavaScript的原型,它可能會幫助你。 – sjahan