这是关于JS变量作用域的第n个问题,但我通读了其余部分,并没有完全得到答案。Javascript变量范围与事件处理程序
var notification = window.webkitNotifications.createNotification(
'image.png', // The image.
'New Post: ',// The title.
'New stuff'// The body.
);
var itemLink = 'http://pathtothefile.com';
notification.onclick = function(itemLink) {
window.focus();
window.open(itemLink,'_blank');
this.cancel();
};
notification.show();
如何获取在全局范围中定义的itemLink以在onclick函数中工作?
将其从参数列表中删除。它只是在那里自动,因为它是一个较小的范围。 – Corbin