HTML and CSS Reference
In-Depth Information
Next, you must create the private method called updateTime . This will update the
current playback time for the track. This method also checks to see whether the
total track length has been reached by the currentTime . If it has, then it will stop
the track.
app.track = function(length){
var setCurrentTime = function(time){
currentTime = time;, currentTime);
var updateTime = function(){
if(currentTime < length){
setCurrentTime(currentTime + updateInterval);
} else {
You will notice that _self is being used here. This is not a global JavaScript
variable but the _self variable that you declared earlier. updateTime is called out
of the scope of the track class/object, so _self maintains a reference back to it.
This is better known as a closure.
Next, you will declare several getter and setters. You create this so that you can
access the private variables outside of the scope of the object. This is handy
when you do not want objects to change properties of another object. For
instance, the currentTime should never be manipulated outside of the object,
but outside objects should be able to find out the current playback time of the
track. Using a getter without a setter prevents outside objects from changing
this value.
app.track = function(length){
this.getCurrentTime = function(){
return currentTime;
this.getLength = function(){
return length;
Search WWH ::

Custom Search