我有這樣一段代碼當前函數名稱:可以在javascript
function MyFunction()
{
$.ajax({
type: "POST",
url: "ajax.php",
dataType: "json",
data: "foo=bar",
error:function(XMLHttpRequest, textStatus, errorThrown)
{
alert(arguments.callee);
},
success: function(jsonObject)
{
//do something
}
});
}
什麼,我想要的是德錯誤scoope內的警報顯示功能名稱,在這種情況下,「MyFunction的」,而是我get是錯誤:函數。
我該如何做到這一點?
我必須失去了一些東西記錄功能。爲什麼不寫'alert('MyFunction');'? –
爲什麼你需要獲取函數的名字?可能你正在接近錯誤的問題。 – Amrit
我想要一些我可以在幾個函數中使用的代碼片段。這樣我可以顯示一個錯誤,並知道錯誤發生在哪個函數中,而不用硬編碼該函數的名稱 –