2015-06-19 89 views
0

请保持良好态度,因为我仍在JavaScript中学习代码。如何在.js中调用一个函数

我正在使用FireFox附加组件,并希望知道如何从外部.js文件调用某个功能。

我有下面的代码main.js文件:

var self = require("sdk/self"); 
var pageMod = require("sdk/page-mod"); 
//var notification = require("notification-box"); 
//var notification = require("notification-box").NotificationBox({ 
//'value': 'important-message', 
//'label': 'Secure Connection Established', 
//'priority': 'WARNING_HIGH', 
//'image': self.data.url("secure.png"), 

//}); 

pageMod.PageMod({ 
    include: "https://*", 
var notification = require("notification-box").NotificationBox({ 
    'value': 'important-message', 
    'label': 'Secure Connection Established', 
    'priority': 'WARNING_HIGH', 
    'image': self.data.url("secure.png"), 

}); 

的NotificationBox函数调用称为通知,box.js另一个外部文件,其目的是显示在的顶部通知栏页。

上述代码的目的是在用户访问HTTPS页面时显示通知。

当我运行上面的代码中,我得到的错误“丢失:后属性列表”

抱歉,如果这是没有意义的。

+0

您的问题是否得到解决? – Noitidart

+1

现在已解决。我改变了代码来调用一个外部的.js文件,而不是调用一个外部函数,然后我可以运行附带条件的打算函数。 – DaE

+0

很感谢分享 – Noitidart

回答

0
'image': self.data.url("secure.png"), 

删除,,它应该是罚款

+0

在firefox中可以留下最后一个逗号 – Noitidart

1

你不能在一个对象的中间粘VAR:

pageMod.PageMod({ 
    include: "https://*", 
    notification: require("notification-box").NotificationBox({ 
     'value': 'important-message', 
     'label': 'Secure Connection Established', 
     'priority': 'WARNING_HIGH', 
     'image': self.data.url("secure.png"), 
    }), 
    'some_other_key': 'some other value' 
}); 
+0

谢谢你的帮助。这工作通过显示实际的通知,但不是在一个安全的页面上。这可能是我需要看的一个单独的问题。 – DaE

相关问题