У меня есть следующие Protoype для интерактивного класса Video Player ...Понимание того, почему я не могу ссылаться на this.property в Javascript «Класс»
// default constructor
function BrightPlayer() { };
// prototypes for basic properties
BrightPlayer.prototype.CurrentCourse = null;
BrightPlayer.prototype.CurrentTopic = null;
BrightPlayer.prototype.CurrentSubTopic = null;
BrightPlayer.prototype.CurrentTimestamp = null;
BrightPlayer.prototype.VideoSelector = null;
BrightPlayer.prototype.VideoObject = null;
BrightPlayer.prototype.Heartbeat = function() {
setInterval(this.ApplicationPulse, 1000);
};
BrightPlayer.prototype.ApplicationPulse = function() {
// javascript errors occurs on the next line.
// VideoObject is undefined.
this.CurrentTimestamp = this.VideoObject.currentTime;
console.log('pulse....');
};
BrightPlayer.prototype.Init = function() {
// My thoughts were that the following line would initialize
// the VideoObject in this instance, and subsequent calls
// in the Application Pulse would have this reference, but it's not working
this.VideoObject = document.getElementById("brightplayer-video");
this.Heartbeat();
};
Класс конкретизируется и Init запускается с моей основной HTML страницы ,
<script>
var Aplayer = new BrightPlayer();
Aplayer.Init();
</script>
Однако, если добавить this.VideoObject = document.getElementById ("brightplayer-видео"); внутри функции ApplicationPulse она работает.
I.E.
BrightPlayer.prototype.ApplicationPulse = function() {
this.VideoObject = document.getElementById("brightplayer-video");
this.CurrentTimestamp = this.VideoObject.currentTime;
console.log('pulse....');
};
Это небрежно, хотя я не хочу, чтобы каждый элемент искал поиск элемента. Мне нужно что-то упустить при попытке связать классы Javascript с классами C#. Любая помощь, которую вы можете дать, будет очень признательна.
Просто используйте JQuery, и вы можете получить видео плеер с $ («# brightplayer-видео»). jQuery довольно эффективен, и я не думаю, что вы увидите замедление на своей веб-странице в браузере. – Mangist