HTML and CSS Reference
In-Depth Information
app.track = function(length){
...
var length = (length * 1000),
currentTime = 0,
interval,
_self = this,
state = this.state.STOPPED,
updateInterval = 1000 / 30;
}
In JavaScript, you can declare variables in a single line, by separating them with
commas. This also works on mobile.
Your first variable, length , will convert the track length passed to the class from
seconds to milliseconds by multiplying it by 1000 . You also set the currentTime
to 0 , and declare a variable called interval . The interval variable is responsible
for holding a reference to the interval declared to repeatedly adjust the timing of
the track.
It seems strange, but you also declare a variable called _self and assign this to
it. This creates a global variable so that any callback events that are called out
of the scope of the object by event listeners will still be able to access the
parent class, as this will be in the scope of the callback event or target and not
the parent class (which, in this case, is track ).
You then declare the current state of the application and set its default state to
this.state.STOPPED .
Finally, you create a new variable called updateInterval , which will be used to
set the number of times per second the time will be updated. For instance, if you
wanted to update the interval 500 times per second, you would set the
updateInterval as updateInterval = 1000 / 500 . Increasing this time will have
an impact on performance, as this affects the frame rate of the Canvas
animation.
You will need to update the currentTime . setCurrentTime is a private method
that will allow you to set the current time for the playback head. It will also make
a callback to any function or method that has assigned itself as the callback to
that method using _self.callbacks.didUpdateTime.call(_self,
currentTime); . call is a method that allows you to invoke a function within the
scope of another object. This will allow the callback function to use this within
its code, and this will be a reference back to the object that made the callback,
rather than the callback function's parent object. The first parameter for call is
the object that you would like to pass scope from. The parameters after that are
the parameters that the callback method will accept.
Search WWH ::




Custom Search