-1
爲什麼這可能是未定義的,我將如何修復它?Javascript - 從第三方調用函數
var a = 1;
var b = 1 + function(){ return 10; }// This could be the wrong way to do it. But it could come from a third party, so it's undeterminded when it's returning. S
console.log(b);
這不是完全清楚你問 - 你可以提供一個更好的例子嗎?在你給的那個函數中,它會簡單地記錄''1function(){return 10;}「' –
你正在接受一個函數(不是返回值)並且給它加1。 '1+函數'是無效的,並給你未定義。你可以將你的函數封裝在一個立即執行的函數中:'1 +(function(){return 10;})();' – h2ooooooo
這與第三方函數有什麼關係?你在哪裏弄不明白?我覺得很多東西在這裏不見了。 –