[gnome-maps/wip/mlundblad/transit-routing: 8/32] 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: 8/32] main: Add array prototype to get last element
- Date: Tue, 14 Feb 2017 21:12:49 +0000 (UTC)
commit f2534c2b48b86a1466340423c77564c9887657e3
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]