Don't use Lang
anymore; it's deprecated and there are better ways. It was created before Function.prototype.bind()
and ES6 Classes. Some reading:
Signal Callbacks
// NOTE: the emitting object is always the first argument,
// so `this` is usually bound to a different object.
function myCallback(sourceObject, arg1) {
if (this === sourceObject)
log('`sourceObject` is correctly bound to `this`');
}
// OLD
sourceObject.connect('signal-name', Lang.bind(myCallback, sourceObject));
// NEW
sourceObject.connect('signal-name', myCallback.bind(sourceObject));
GObject Classes
// OLD
const MyLegacyClass = new Lang.Class({
GTypeName: 'MyLegacyClass',
Extends: GObject.Object,
_init(a, b) {
this.parent(a);
this.b = b;
}
});
// NEW
const MyClass = GObject.registerClass({
GTypeName: 'MyLegacyClass',
}, class MyClass extends GObject.Object {
_init(a, b) {
super._init(a);
this.b = b;
}
);