我正在上课,我有以下问题。我有些电视之间有一些区别。所以,我正在考虑在我的init方法上解决这个问题。例如:
this._init = function() {
switch(this._defaultOptions.qualTV) {
case TV_PANASONIC:
this._video = playerPanasonic;
Player.prototype.play = function() { this._video.play(); }
Player.prototype.pause = function() { this._video.pause(); }
break;
case TV_PHILLIPS:
this._video = document.getElementById("video_drm_philips");
Player.prototype.play = function() { this._video.play(1); }
Player.prototype.pause = function() {
this._video.play(0);
clearInterval(buffer_video); }
break;
default:
this._video = document.querySelector("video") || document.getElementById("stream");
Player.prototype.play = function() { this._video.play(); }
Player.prototype.pause = function() { this._video.pause(); }
}
}
我怀疑的是,这是最好的做法。上面或下面的代码更好吗?
Player.prototype._pause = function() {
if (this._defaultOptions.qual_tv === "smarttv-ph" || this._defaultOptions.qual_tv === "lg") {
this._video.play(0);
}
this._video.pause();
}
如果,最好的做法是第一个,我怎样才能增加一些特定于每个电视的代码?