Skip to content

Commit

Permalink
fix(HtmlTrackElementList): allow to reference by index via bracket no…
Browse files Browse the repository at this point in the history
…tation (#3776)

Previously, HtmlTrackElementList did not actually let you access HtmlTrackElements via bracket notation (`list[0]`) unlike TextTrackList. This adds that feature.
  • Loading branch information
ldayananda authored and gkatsev committed Nov 14, 2016
1 parent 72fcb6c commit 430be94
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/js/tracks/html-track-element-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,20 @@ class HtmlTrackElementList {
}

addTrackElement_(trackElement) {
this.trackElements_.push(trackElement);
const index = this.trackElements_.length;

if (!('' + index in this)) {
Object.defineProperty(this, index, {
get() {
return this.trackElements_[index];
}
});
}

// Do not add duplicate elements
if (this.trackElements_.indexOf(trackElement) === -1) {
this.trackElements_.push(trackElement);
}
}

getTrackElementByTrack_(track) {
Expand Down

0 comments on commit 430be94

Please sign in to comment.