我有一個函數作爲構造函數在調用時被調用程序中的函數定義,但從來沒有到函數體。我忽略了這種情況的普遍原因嗎?下面的示例代碼:Javascript函數調用將不會進入函數體
myconstructor.js
function MyConstructor(optionalParam) { //this breakpoint gets hit
var newobj = {}; //breakpoint never hit
//code to check for null parameter
//other code
};
main.js
var myConstructor = new MyConstructor();
一定有什麼東西我都忽略了,但我看不出那是什麼。 firefox/firebug和VS都不報告錯誤或警告。
謝謝!
不確定,因爲我不使用JavaScript,但你需要這樣發送'optionalParam'給構造函數,所以使用'var myConstructor = new MyConstructor(optionalParam);'。 – Kyra 2010-06-16 19:45:07
MyConstructor是否會返回任何內容?如果沒有返回值,變量myConstructor最終應該是未定義的。 – 2010-06-16 19:46:15
你有沒有嘗試把'console.log()'放在函數體內? – 2010-06-16 19:50:36