From a664bcebac0c101dba22e5ffa53633be1cbeb2d3 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Wed, 30 Apr 2014 11:17:25 -0700 Subject: [PATCH] Switch to Array.forEach() where possible. --- static/cosmopolite.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/static/cosmopolite.js b/static/cosmopolite.js index e41b8c6..3afc18c 100644 --- a/static/cosmopolite.js +++ b/static/cosmopolite.js @@ -23,17 +23,17 @@ cosmopolite.Client = function(opt_callbacks, opt_urlPrefix, opt_namespace) { this.stateCache_ = {}; - var scripts = [ + var scriptUrls = [ 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js', '/_ah/channel/jsapi', ]; - this.numScriptsToLoad_ = scripts.length; - for (var i = 0; i < scripts.length; i++) { + this.numScriptsToLoad_ = scriptUrls.length; + scriptUrls.forEach(function(scriptUrl) { var script = document.createElement('script'); - script.src = scripts[i]; + script.src = scriptUrl; script.onload = this.onLoad_.bind(this); document.body.appendChild(script); - } + }, this); }; cosmopolite.Client.prototype.onLoad_ = function() { @@ -170,9 +170,7 @@ cosmopolite.Client.prototype.onCreateChannel_ = function(data) { }); // Handle messages that were immediately available as if they came over the // channel. - for (var i = 0; i < data['messages'].length; ++i) { - this.onServerMessage_(data['messages'][i]); - } + data['messages'].forEach(this.onServerMessage_, this); }; cosmopolite.Client.prototype.onSocketOpen_ = function() {