[gnome-maps/wip/mlundblad/transit-routing: 8/32] main: Add array prototype to get last element



commit 04e5a1f2e8790672cb76c3951814713d806d3991
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]