【发布时间】:2016-01-03 10:35:05
【问题描述】:
我正在编写一个小的 mozilla 插件,但我在两个课程上遇到了同样的问题。
var { ActionButton } = require('sdk/ui/button/action');
var MateButton = function(mate)
{
var self = this;
myMate: mate,
button: ActionButton(
{
id: "my-button",
label: self.myMate.message_OFF,
icon:
{
"16": self.myMate.icon_OFF,
}
}),
onChange: function()
{
var mate = self.myMate;
var icon_tmp = ((mate.online == true) ? mate.icon_ON : mate.icon_OFF);
var message_tmp = ((mate.online == true) ? mate.message_ON : mate.message_OFF);
self.button.state("window",
{
"label": message_tmp,
"icon":
{
"16": icon_tmp,
}
});
}
};
exports.MateButton = MateButton;
问题:
控制台在“onChange:function()”之前发现错误:SyntaxError:missing ;声明之前。
我尝试将“,”替换为“;”但错误变为“函数语句需要名称”。
之前我也试过删除函数onChange和冒号,但是错误转移到了按钮定义上。
谁能帮帮我?
【问题讨论】:
-
删除
,这里"16": icon, -
myMate: mate;,替换; -
是的,谢谢,我更改了“this.myMate = mate;”通过“我的伴侣:伴侣;”并忘记更改“;”。但它之前已经犯了这些错误0
-
这一切都搞混了。你一半使用函数声明,一半使用对象声明。
-
是的,没错。这是因为我需要一些对象和一种方法。