Hello Jay,

>From /usr/share/gnome-js/signals.js

function _connect(name, callback) {

The connect takes two arguments.

The callback argument, without binding additional arguments to 
the callback, consists of only the function and its first and 
second argument. 

lang.bind as noted in the comments below provides for the use
of "this" in the body of the callback function and binding
additional arguments to the callback function.

>From /usr/share/gnome-js/lang.js

/**
 * Binds obj to callback. Makes it possible to refer to "obj"
 * using this within the callback.
 * @param {object} obj the object to bind
 * @param {function} callback callback to bind obj in
 * @param arguments additional arguments to the callback
 * @returns: a new callback
 * @type: function
 */

You will not see many examples of using the binding of additional 
arguments because of "this" being available in the callback function.

Regards,
Norman

On Wed, 2015-09-23 at 09:09 +0200, Jay Strict wrote:
> It is very useful, as this is exactly how it works now.
> Thank you.
>       
> What is the reason that without Lang.bind() the function can access
> the
> first two arguments ("emitter" and "event") but not the third one?
> 
> And why is it different with Lang.bind()?
> 
> Regards
> Jay
> 
> On 22.09.2015 19:05, Norman L. Smith wrote:
> > 
> > You need to use Lang.bind.
> > 
> > See 
> > https://paste.fedoraproject.org/270197/
> > or
> > http://ur1.ca/nu9t9
> > 
> > 
> > Hope this is useful.
> > 
> > Norman
> > 
> > On Tue, 2015-09-22 at 11:44 +0200, Jay Strict wrote:
> > > I am writing a gnome-shell extension and I am trying to connect
> > > the
> > > 'activate'-signal of a PopupMenuItem to a callback function like
> > > this:
> > > 
> > > 
> > > =================================================================
> > > ====
> > > =
> > > let item = new PopupMenu.PopupMenuItem("test")
> > > item.connect(
> > >     'activate',
> > >     function(emitter, event, user_data) {
> > >         Main.notifyError("user_data: " + user_data);
> > >     },
> > >     "test1",
> > >     "test2",
> > >     "test3",
> > >     "test4");
> > > this.folderMenu.addMenuItem(item);
> > > =================================================================
> > > ====
> > > =
> > > 
> > > I expected the output to be "user_data: test1".
> > > However, when I click on the PopupMenuItem, the output is
> > > "user_data:
> > > undefined".
> > > How can I assign some user_data to this signal?
> > > 
> > > 
> > > Thank you in advance.
> > > Jay
> > > _______________________________________________
> > > gnome-shell-list mailing list
> > > gnome-shell-list@gnome.org
> > > https://mail.gnome.org/mailman/listinfo/gnome-shell-list
_______________________________________________
gnome-shell-list mailing list
gnome-shell-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gnome-shell-list

Reply via email to