HTML and CSS Reference
In-Depth Information
previous code sample. The simple answer is that the setters haven't been
declared yet, so calling the methods will create a JavaScript error.
When you declare a normal named function in JavaScript, the interpreter will
look for the function when it's called, regardless of its placement in the script.
However, when you assign a function to a variable, you have to wait until that
assignment happens before calling the function.
To get around this, you must either put all of your initialization code at the end of
the object, or wrap it in a method at the top and call it from the bottom. I have
opted for the later, as getters and setters tend to create a lot of white noise, and
scrolling through lots of what feels like pointless code to get to your main code
is a bit irritating. You can see that the init method is called toward the end of
the object in the previous example.
The next thing to do is to create the getters and setters.This is a really simple
task. Just to recap, the getters return an instance variable, and the setters
assign values to instance variables as anything outside the object can't modify
the instance variables from outside of the object.
The getters and setters are fairly self explanitory, you can see in the following
code.
...
app.model.videosource = function appModelVideoSource(url, format){
...
/**
* Getters and setters
*/
/**
* Gets the url of the video source
* @return {String}
*/
this.getUrl = function(){
return _url;
}
/**
* Sets the url of the video source
* @param {String} url
*/
this.setUrl = function(url){
_url = url;
}
/**
* Gets the mimetype of the video source
* @return {app.type.format}
 
Search WWH ::




Custom Search