[gnome-maps/wip/mlundblad/transit-routing: 1/23] main: Add array prototype to get last element
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/transit-routing: 1/23] main: Add array prototype to get last element
- Date: Fri, 10 Feb 2017 08:48:45 +0000 (UTC)
commit c9f4ff971018a9b0d318d2c1c6623a70152e863a
Author: Marcus Lundblad <ml update uu se>
Date: Fri Feb 10 09:43:39 2017 +0100
main: Add array prototype to get last element
Add an array prototype function to get the last element.
This saves having to do some array[array.length - 1]
contructs later on.
TODO: if we grow more prototype definitions further along
this could be moved to a separate module.
https://bugzilla.gnome.org/show_bug.cgi?id=755808
src/main.js | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/src/main.js b/src/main.js
index 9d584ea..d93f040 100644
--- a/src/main.js
+++ b/src/main.js
@@ -43,6 +43,16 @@ pkg.require({ 'cairo': '1.0',
const Application = imports.application;
function main(args) {
+ /* Add prototype to get last element of an array.
+ * TODO: if we get more of these, might move initing
+ * to a decicated Prototypes modules.
+ */
+ if (!Array.prototype.last) {
+ Array.prototype.last = function() {
+ return this[this.length - 1];
+ }
+ }
+
let application = new Application.Application();
return application.run(args);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]