Jas*_* ap 3 gnome gnome-shell gjs
我最近正在研究 Gnome shell 扩展。我查看了一些代码,如下所示:
\nconst Lang = imports.lang;\n\nconst extension = new Lang.Class({...}\xef\xbc\x89\nRun Code Online (Sandbox Code Playgroud)\n我在GJS中找不到任何有关Lang的信息。
\n相关的开发手册应该去哪里找?
\nDon'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));
Run Code Online (Sandbox Code Playgroud)
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;
}
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
441 次 |
| 最近记录: |