我發現了與我使用完全相同的標題的線程,但我無法真正獲得與我的問題的聯繫(我對JavaScript很陌生,可能是此問題)。JavaScript:不是函數
我正在擴展MediaWiki VisualEditor。其中一部分是複製一個js類/腳本。
這是我得到的錯誤:
[...]
ve.ui.TextColorSearchDialog.static.textColorSearchWidget = ve.ui.TextColorSearchWidget;
/* Methods */
/**
* @inheritdoc
*/
ve.ui.TextColorSearchDialog.prototype.initialize = function() {
ve.ui.TextColorSearchDialog.super.prototype.initialize.apply(this, arguments);
this.searchWidget = new this.constructor.static.textColorSearchWidget({
$: this.$
}).on('select', this.onSearchWidgetSelect.bind(this));
this.$body.append(this.searchWidget.$element);
};
[...]
我得到這個錯誤:
Uncaught TypeError: this.constructor.static.textColorSearchWidget is not a function
(初始化函數的第二行)
雖然這項工作完全正常(的原始文件):
[...]
ve.ui.LanguageSearchDialog.static.languageSearchWidget = ve.ui.LanguageSearchWidget;
/* Methods */
/**
* @inheritdoc
*/
ve.ui.LanguageSearchDialog.prototype.initialize = function() {
ve.ui.LanguageSearchDialog.super.prototype.initialize.apply(this, arguments);
this.searchWidget = new this.constructor.static.languageSearchWidget({
$: this.$
}).on('select', this.onSearchWidgetSelect.bind(this));
this.$body.append(this.searchWidget.$element);
};
[...]
我也嘗試在我的文件的第一行中分配ve.ui.LanguageSearchWidget而不是ve.ui.TextColorSearchWidget,以查看它是否與ve.ui.TextColorSearchWidget的構造函數有關,但是我得到了同樣的錯誤我猜這個問題必須在我發佈的部分 - 我不明白,因爲它與TextColor替換的語言完全相同? (Ofc我也創建了ve.ui.TextColorSearchWidget文件)。
編輯:如果是相關的,這些都是全類:
原LanguageSearchDialog:http://pasted.co/4a429272
我原來LanguageSearchDialog的複製,TextColorSearchDialog: http://pasted.co/d2dbdd70
原來的窗口小部件(其在工作的LanguageSearchDialog中創建):http://pasted.co/89daa63b
我的複製原來的Widget我TextcolorSearchDialog:http://pasted.co/164194ce
不知道你的瀏覽器/環境,但你應該得到一個錯誤消息,包含有關什麼不是函數和行號的信息。你能看到嗎? –
嘿,是啊,我已經把信息編輯到帖子中,只是忘了它,對不起。 –
請執行'console.log(new this.constructor.static);'在這行的上方..'this.searchWidget = ...'併發布它。 –