... | ... | @@ -4,7 +4,9 @@ |
|
|
|
|
|
GObjects can be constructed with the `new` operator, just like JavaScript objects, and usually take an Object map of properties.
|
|
|
|
|
|
The object that you pass to `new` (e.g. `Gtk.Label` in `let label = new Gtk.Label()`) is the **constructor object**, which differs from the **class object** because it can contain constructor methods and static methods such as `Gio.File.new_for_path()`.
|
|
|
The object that you pass to `new` (e.g. `Gtk.Label` in `let label = new Gtk.Label()`) is the **constructor object**, that contains constructor methods and static methods such as `Gio.File.new_for_path()`.
|
|
|
It's different from the **prototype object** containing instance methods.
|
|
|
For more information on JavaScript's prototypal inheritance, this [blog post][understanding-javascript-prototypes] is a good resource.
|
|
|
|
|
|
```js
|
|
|
let label = new Gtk.Label({
|
... | ... | @@ -18,6 +20,8 @@ let label = new Gtk.Label({ |
|
|
let file = Gio.File.new_for_path('/proc/cpuinfo');
|
|
|
```
|
|
|
|
|
|
[understanding-javascript-prototypes]: https://javascriptweblog.wordpress.com/2010/06/07/understanding-javascript-prototypes/
|
|
|
|
|
|
### Subclassing GObjects
|
|
|
|
|
|
GObjects have facilities for defining properties, signals and implemented interfaces. Additionally, Gtk objects support defining a CSS name and composite template.
|
... | ... | |