HTML and CSS Reference
In-Depth Information
*/
for(var i = 0; i < sources.length; i++){
_self.addSource(sources[i]);
}
}
/**
* Adds a source to the sources array
* @param {app.model.videosource} source
*/
this.addSource = function(source){
_sources.push(source);
}
...
}
As you can see, the accessors follow the same implementation from the pet
example shown earlier in this chapter.
You might also want to add some type of filtering on the _length setter so that
any value is parsed as an integer to prevent any issues within the model. You
can use the parseInt method in the setter's implementation. This will ensure
that any value passed to the model will be an integer or zero. The setter can be
seen in the following code snippet.
app.model.video = function appModelVideo(title, length, posterframe){
...
/**
* Sets the length of the video in milliseconds
* @param {Integer} length
*/
this.setLength = function(length){
/**
* Use parseInt here just to ensure the length
* is an integer. If it's not, then it will
* return NaN. The isNaN method will check to
* see whether the value is not a number.
*/
_length = parseInt(length);
if(isNaN(_length)){
_length = 0;
}
}
...
}
You can now complete the Video model, which should look like the following.
 
Search WWH ::




Custom Search