diff --git a/src/js/__tests__/treeCompare.spec.js b/src/js/__tests__/treeCompare.spec.js index 9b007d0c..ab71ec35 100644 --- a/src/js/__tests__/treeCompare.spec.js +++ b/src/js/__tests__/treeCompare.spec.js @@ -1,5 +1,4 @@ var TreeCompare = require('../graph/treeCompare'); -var _ = require('underscore'); var loadTree = function(treeString) { return TreeCompare.convertTreeSafe(treeString); @@ -13,7 +12,8 @@ var testMethod = function(compareMethod, goalTreeString, cases, options) { cases[goalTreeString] = true; } - _.each(cases, function(value, actualTree) { + Object.keys(cases).forEach(function(actualTree) { + var value = cases[actualTree]; var isEqual = TreeCompare.dispatch(compareMethod, goalTreeString, actualTree); if (isEqual !== value) { console.log('this goal tree', loadTree(goalTreeString)); @@ -21,7 +21,7 @@ var testMethod = function(compareMethod, goalTreeString, cases, options) { console.log('for this value', value); } expect(isEqual).toBe(value); - }); + }.bind(this)); }; describe('Tree Compare', function() { diff --git a/src/js/git/gitShim.js b/src/js/git/gitShim.js index fb015b5d..b9573ed4 100644 --- a/src/js/git/gitShim.js +++ b/src/js/git/gitShim.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Q = require('q'); var Main = require('../app'); diff --git a/src/js/level/builder.js b/src/js/level/builder.js index b94ab8ca..38e33ec0 100644 --- a/src/js/level/builder.js +++ b/src/js/level/builder.js @@ -316,7 +316,7 @@ var LevelBuilder = Level.extend({ ] }); askForHintView.getPromise() - .then(this.defineHint, this)) + .then(this.defineHint.bind(this)) .fail(function() { this.level.hint = {'en_US': ''}; }.bind(this)) diff --git a/src/js/level/disabledMap.js b/src/js/level/disabledMap.js index ee12cd5a..a63252e3 100644 --- a/src/js/level/disabledMap.js +++ b/src/js/level/disabledMap.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var intl = require('../intl'); var Commands = require('../commands'); @@ -25,7 +24,7 @@ DisabledMap.prototype.getInstantCommands = function() { }); }; - _.each(this.disabledMap, function(val, disabledCommand) { + Object.keys(this.disabledMap).forEach(function(disabledCommand) { // XXX get hold of vcs from disabledMap var vcs = 'git'; disabledCommand = disabledCommand.slice(vcs.length + 1); @@ -35,7 +34,7 @@ DisabledMap.prototype.getInstantCommands = function() { ' has no regex matching'); } instants.push([gitRegex, onMatch]); - }); + }.bind(this)); return instants; }; diff --git a/src/js/level/index.js b/src/js/level/index.js index eda1b705..669a5129 100644 --- a/src/js/level/index.js +++ b/src/js/level/index.js @@ -368,16 +368,16 @@ var Level = Sandbox.extend({ initGitShim: function(options) { // ok we definitely want a shim here this.gitShim = new GitShim({ - beforeCB: this.beforeCommandCB, this), - afterCB: this.afterCommandCB, this), - afterDeferHandler: this.afterCommandDefer, this) + beforeCB: this.beforeCommandCB.bind(this), + afterCB: this.afterCommandCB.bind(this), + afterDeferHandler: this.afterCommandDefer.bind(this) }); }, undo: function() { this.gitCommandsIssued.pop(); Level.__super__.undo.apply(this, arguments); - }.bind(this) + }.bind(this), afterCommandCB: function(command) { if (command.get('error')) { diff --git a/src/js/mercurial/commands.js b/src/js/mercurial/commands.js index 5bd6461c..acf14fcc 100644 --- a/src/js/mercurial/commands.js +++ b/src/js/mercurial/commands.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var intl = require('../intl'); var GitCommands = require('../git/commands'); diff --git a/src/js/models/collections.js b/src/js/models/collections.js index cd4b3665..59800aa2 100644 --- a/src/js/models/collections.js +++ b/src/js/models/collections.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Q = require('q'); var Backbone = require('backbone'); diff --git a/src/js/sandbox/index.js b/src/js/sandbox/index.js index 06dc841f..8c149cb0 100644 --- a/src/js/sandbox/index.js +++ b/src/js/sandbox/index.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Q = require('q'); var Backbone = require('backbone'); @@ -68,7 +67,7 @@ var Sandbox = Backbone.View.extend({ initGitShim: function(options) { this.gitShim = new GitShim({ - beforeCB: this.beforeCommandCB, this) + beforeCB: this.beforeCommandCB.bind(this) }); }, @@ -83,7 +82,7 @@ var Sandbox = Backbone.View.extend({ Main.getEventBaton().stealBaton('levelExited', this.levelExited, this); this.insertGitShim(); - }.bind(this) + }.bind(this), releaseControl: function() { // we will be handling commands that are submitted, mainly to add the sanadbox diff --git a/src/js/views/builderViews.js b/src/js/views/builderViews.js index ef260524..40563e67 100644 --- a/src/js/views/builderViews.js +++ b/src/js/views/builderViews.js @@ -68,14 +68,14 @@ var MarkdownGrabber = ContainedBase.extend({ // do button stuff var buttonDefer = Q.defer(); buttonDefer.promise - .then(this.confirmed, this)) - .fail(this.cancelled, this)) + .then(this.confirmed.bind(this)) + .fail(this.cancelled.bind(this)) .done(); var confirmCancel = new Views.ConfirmCancelView({ deferred: buttonDefer, destination: this.getDestination() - }.bind(this) + }.bind(this)); } this.updatePreview(); @@ -98,7 +98,7 @@ var MarkdownGrabber = ContainedBase.extend({ keyup: function() { if (!this.throttledPreview) { this.throttledPreview = _.throttle( - this.updatePreview, this), + this.updatePreview.bind(this), 500 ); } @@ -107,7 +107,7 @@ var MarkdownGrabber = ContainedBase.extend({ getRawText: function() { return this.$('textarea').val(); - }.bind(this) + }.bind(this), exportToArray: function() { return this.getRawText().split('\n'); @@ -155,7 +155,7 @@ var MarkdownPresenter = ContainedBase.extend({ .fail(function() { this.deferred.reject(); }.bind(this)) - .done(this.die, this)); + .done(this.die.bind(this)); } this.show(); @@ -230,8 +230,8 @@ var DemonstrationBuilder = ContainedBase.extend({ }); buttonDeferred.promise - .then(this.confirmed, this)) - .fail(this.cancelled, this)) + .then(this.confirmed.bind(this)) + .fail(this.cancelled.bind(this)) .done(); }, @@ -243,7 +243,7 @@ var DemonstrationBuilder = ContainedBase.extend({ options: this.getExportObj() }] }); - }.bind(this) + }.bind(this), getExportObj: function() { return { diff --git a/src/js/views/index.js b/src/js/views/index.js index a81bae6e..005c82f2 100644 --- a/src/js/views/index.js +++ b/src/js/views/index.js @@ -107,7 +107,7 @@ var GeneralButton = ContainedBase.extend({ click: function() { if (!this.clickFunc) { this.clickFunc = _.throttle( - this.sendClick, this), + this.sendClick.bind(this), 500 ); } @@ -578,11 +578,11 @@ var CanvasTerminalHolder = BaseView.extend({ // If the entire window gets resized such that the terminal is outside the view, then // move it back into the view, and expand/shrink it vertically as necessary. - $(window).on('resize', _.debounce(this.recalcLayout, this), 300)); + $(window).on('resize', _.debounce(this.recalcLayout.bind(this), 300)); if (options.additionalClass) { this.$el.addClass(options.additionalClass); - }.bind(this) + } }, getAnimationTime: function() { return 700; }, diff --git a/src/js/views/levelDropdownView.js b/src/js/views/levelDropdownView.js index 7c95119f..889dd5fe 100644 --- a/src/js/views/levelDropdownView.js +++ b/src/js/views/levelDropdownView.js @@ -42,7 +42,7 @@ var LevelDropdownView = ContainedBase.extend({ this.navEvents = _.clone(Backbone.Events); this.navEvents.on('clickedID', _.debounce( - this.loadLevelID, this), + this.loadLevelID.bind(this), 300, true )); @@ -60,7 +60,7 @@ var LevelDropdownView = ContainedBase.extend({ enter: 'positive' }, wait: true - }.bind(this) + }); this.sequences = LevelStore.getSequences(); this.sequenceToLevels = LevelStore.getSequenceToLevels(); diff --git a/src/js/visuals/animation/animationFactory.js b/src/js/visuals/animation/animationFactory.js index 04f6df20..e0c3dbfb 100644 --- a/src/js/visuals/animation/animationFactory.js +++ b/src/js/visuals/animation/animationFactory.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var Q = require('q'); @@ -76,14 +75,14 @@ AnimationFactory.highlightEachWithPromise = function( toHighlight, destObj ) { - _.each(toHighlight, function(commit) { + toHighlight.forEach(function(commit) { chain = chain.then(function() { return this.playHighlightPromiseAnimation( commit, destObj ); }.bind(this)); - }, this); + }.bind(this)); return chain; }; diff --git a/src/js/visuals/animation/index.js b/src/js/visuals/animation/index.js index 6f189375..cd0784c4 100644 --- a/src/js/visuals/animation/index.js +++ b/src/js/visuals/animation/index.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Q = require('q'); var Backbone = require('backbone'); var GlobalStateActions = require('../../actions/GlobalStateActions'); diff --git a/src/js/visuals/visualization.js b/src/js/visuals/visualization.js index 5d4d03a0..3eddd343 100644 --- a/src/js/visuals/visualization.js +++ b/src/js/visuals/visualization.js @@ -91,7 +91,7 @@ var Visualization = Backbone.View.extend({ this.shown = false; this.setTreeOpacity(0); // reflow needed - process.nextTick(this.fadeTreeIn, this)); + process.nextTick(this.fadeTreeIn.bind(this)); this.customEvents.trigger('gitEngineReady'); this.customEvents.trigger('paperReady'); @@ -99,7 +99,7 @@ var Visualization = Backbone.View.extend({ clearOrigin: function() { delete this.originVis; - }.bind(this) + }.bind(this), makeOrigin: function(options) { // oh god, here we go. We basically do a bizarre form of composition here, @@ -186,7 +186,7 @@ var Visualization = Backbone.View.extend({ show: function() { $(this.paper.canvas).css('visibility', 'visible'); - setTimeout(this.fadeTreeIn, this), 10); + setTimeout(this.fadeTreeIn.bind(this), 10); this.originToo('show', arguments); this.myResize(); }, @@ -196,7 +196,7 @@ var Visualization = Backbone.View.extend({ this.setTreeOpacity(1); this.originToo('showHarsh', arguments); this.myResize(); - }.bind(this) + }.bind(this), resetFromThisTreeNow: function(treeString) { this.treeString = treeString;