Created
November 21, 2013 01:28
-
-
Save ThomasBurleson/7574511 to your computer and use it in GitHub Desktop.
Refactor Dash.js JavaScript class - to use AMD pattern, eliminate requirement to construct with `new`, remove unnecessary use of Promises.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MediaPlayer.rules.BaseRulesCollection = function () { | |
"use strict"; | |
var rules = []; | |
return { | |
downloadRatioRule: undefined, | |
insufficientBufferRule: undefined, | |
//limitSwitchesRule: undefined, | |
getRules: function () { | |
return Q.when(rules); | |
}, | |
setup: function () { | |
var self = this; | |
self.getRules().then( | |
function (r) { | |
r.push(self.downloadRatioRule); | |
r.push(self.insufficientBufferRule); | |
//r.push(self.limitSwitchesRule); | |
} | |
); | |
} | |
}; | |
}; | |
MediaPlayer.rules.BaseRulesCollection.prototype = { | |
constructor: MediaPlayer.rules.BaseRulesCollection | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While reviewing the very interesting Git project Dash.js, I noticed some repeating usages that seem unnecessary, dangerous, or verbose.
Below is a refactored version of the above class:
Items of note:
rules
arraythis
scope and the requirement to usenew BaseRulesCollection()