rookie question - let, scope, and callbacks
- From: Amy C <mathematical coffee gmail com>
- To: gnome-shell-list gnome org
- Subject: rookie question - let, scope, and callbacks
- Date: Sat, 26 May 2012 00:02:36 +1000
Hi all,
I've made myself a whole bunch of PopupSwitchMenuItems and tried to
connect their 'toggled' callback to the same function, passing the
name of the menu item as a parameter:
this._items = {};
this._toggleNames = {
ignorePopups : _('Ignore popups'),
ignoreMaximised: _('Ignore maximised windows'),
DEBUG: _('Debug mode')
};
for ( let propName in this._toggleNames ) {
this._items[propName] = new
PopupMenu.PopupSwitchMenuItem(this._toggles[propName], false);
this._items[propName].connect('toggled', Lang.bind(this,
function() { log(('toggled: ' + propName)); }));
// ... rest of code
}
However when I toggle any of the items, I always get "toggled: DEBUG"
as the output (this also occurs when I remove the Lang.bind, although
I will eventually need it).
Why is this happening? propName is only declared in the for statement,
and I thought the use of 'let' made sure that `propName` didn't
default to the last value that it had for the callbacks, i.e. DEBUG.
I'm using GNOME 3.4.
cheers!
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]