GNOME Bugzilla – Bug 790301
extensions: Modernize JS usage
Last modified: 2017-11-25 02:28:47 UTC
First fix a couple of style issues, then modernize the style to use: - arrow notation - method syntax - ES6 classes - GJS' ES6 class wrapper for GObject classes - Function.prototype.bind() Doing a similar cleanup for gnome-shell is unfortunately harder: While ES6 classes can inherit from Lang.Class, the reverse is not true. So this will need some more thought (or at least enough heads-up before pulling the switch) to not break extensions left and right ...
Created attachment 363523 [details] [review] cleanup: Fix some coding style issues
Created attachment 363524 [details] [review] cleanup: Replace tabs with spaces
Created attachment 363525 [details] [review] cleanup: Use arrow-notation for anonymous functions Arrow notation is great, but as we only started using it recently, we currently have a wild mix of Lang.bind(), function() and () => {}. To make the style consistent again, change all anonymous functions to arrow notation.
Created attachment 363526 [details] [review] cleanup: Use method syntax Modern javascript has a short-hand for function properties, embrace it for better readability and to prepare for porting to ES6 classes.
Created attachment 363527 [details] [review] cleanup: Port non-GObject classes to ES6 classes ES6 finally adds standard class syntax to the language, so we can replace our custom Lang.Class framework with the new syntax. Any classes that inherit from GObject will need special treatment, so limit the port to regular javascript classes for now.
Created attachment 363528 [details] [review] cleanup: Port GObject classes to ES6 classes GJS added API for defining GObject classes with ES6 class syntax last cycle, use it to port the remaining Lang.Class classes to the new syntax.
Created attachment 363529 [details] [review] cleanup: Get rid of Lang.bind() After replacing Lang.Class with ES6 classes and adopting arrow notation for anonymous callbacks, we only use the Lang module to bind `this` to named callbacks. However since ES5, this functionality is already provided by Function.prototype.bind() - in fact, Lang.bind() itself uses it when no extra arguments are specified. So just use the built-in function directly instead of the wrapper.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gnome-shell-extensions/issues/30.