我有一個名爲FileController的'class',其中存儲了一個靜態屬性。對於它的價值,我用它來識別一個事件類型。當我嘗試訪問字符串作爲'類'的靜態屬性時,它的未定義。我想知道爲什麼?爲什麼這個靜態屬性未定義?如何訪問Javascript中的靜態屬性
FileController = function(galId)
{
FileController.GALLERY_UPLOAD_START = "galleryUploadStart";
}
//然後在另一個文件...
function initDragSystem()
{
console.log('@initDragSystem FileController ' + FileController); //Traces out the constructor method
console.log('@initDragSystem FileController.GALLERY_UPLOAD_START = ' + FileController.GALLERY_UPLOAD_START) //traces out 'undefined'
}
將屬性初始化行移到函數外,所以不必爲了定義而調用它 – Ian