2016-01-20 167 views
0

我发现了与我使用完全相同的标题的线程,但我无法真正获得与我的问题的联系(我对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

+0

不知道你的浏览器/环境,但你应该得到一个错误消息,包含有关什么不是函数和行号的信息。你能看到吗? –

+0

嘿,是啊,我已经把信息编辑到帖子中,只是忘了它,对不起。 –

+0

请执行'console.log(new this.constructor.static);'在这行的上方..'this.searchWidget = ...'并发布它。 –

回答

0

好了,我没能找出是什么原因造成的问题,但在这种情况下,我可以通过简单地绕过ve.ui.TextColorSearchDialog.static.textColorSearchWidget并把ve.ui.TextColorSearchWidget直接进入通话,导致

修复

this.searchWidget = new ve.ui.TextColorSearchWidget({ $: this.$ [...]

摆脱了错误。