Create the document structure
This is a example of the HTML document structure
Here is the New Semantic Elements in HTML5
- header
- nav
- section
- article
- aside
- figure
- figcaption
- footer
- details
- summary
- mark
- time
to replace things like this:
also i found a great post about Semantic Markup and Page Layout
Write code that interacts with UI controls
To Programmatically add and modify HTML elements right now we have a lot of libraries and frameworks like jquery, knockoutjs, dojo, etc.. but here is a basic example how to do this using javascript at the DOM (Document Object Model), but wait, what’s is the DOM? the W3C defines like
The Document Object Model is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents.
We can said that, is a API that helps to give form to your HTML and you can access to manipulate to change your content. So here is the example:
and here is some link for more information:
- http://www.elated.com/articles/changing-page-elements-with-the-dom/
- http://krasimirtsonev.com/blog/article/Convert-HTML-string-to-DOM-element
About the intermedia controls the idea is to use new features to HTML5 to embed video and audio content with this elements:
- video
- audio
and with the audio
and of course here is more references for more information:
- http://www.w3schools.com/tags/ref_av_dom.asp
- http://www.emmanuelndayiragije.com/comment-building-html5-media-video-audio-controls-with-javascript
- http://www.adobe.com/devnet/html5/articles/html5-multimedia-pt1.html
Implement HTML5 canvas can be a little difficult, with canvas you can draw 3D and 2D graphics with coordinate system, animations, using JavaScript, also you can use equations, matrix multiplication, sin, cos, etc.. at this point is when will turn a little complex, but in this case i only show a easy example how to use this element.
you get something like this
more information here:
- http://msdn.microsoft.com/en-us/library/gg589510%28v=vs.85%29.aspx
- http://www.w3schools.com/tags/ref_canvas.asp
Also we have SVG (Scalable Vector Graphics) to create 2D-graphics, SVG is a language type diagrams like Pie charts, Two-dimensional graphs in an X,Y coordinate system, graphic application in XML, etc… This is a simple example that i stole how to use SVG:
and of course, I found another great link about SVG and Canvas in the next link:
Apply styling to HTML elements programmatically
Here is a simple example how to change some element:
also we can change the position adding this two lines
so this should be looks like this
Implement HTML5 APIs
Storage APIs
Two new features:
- local Storage
- session Storage
Here’s is a example for local Storage:
and you can delete the local Storage with this
and for the Session Storage
but what’s the difference? the sessionStore deleted when you close the browser because is designed for scenarios where the user is carrying out a single transaction
AppCache API
So what is the AppCahe API? is that awesome application that helps when you don’t have a internet connection and how it works? well, like this
First, you need to call an attribute called manifest in each page that we want to put in cache.
manifest: that is text file that contain the resources to cache own page
also you cant put url’s like this
for more information:
Geolocation API
The geolocation is basically to get the geographical position of a user or ours, share the location with other web sites, etc.. Also you can integrate with Google and Bing Maps.
Establish the scope of objects and variables
With javascript variables that you declare can be global or local.
If you declare some variable outside of any function is global and variables create inside of any function are local variables.
One of the important things and good practices is that you should avoid creating global objects unless they are absolutely necessary because sometimes when we work with a third parties if we don’t named that variables we may have risk of naming collision and there a different ways to do this, so I stole this little example of a common way to do this
the problem with this, is not maintainable because if we change the name of the variable we will have a bit of work with the rest but it works
I found this great posts for more depth ways to do this
- http://www.zendesk.com/blog/keep-javascript-libraries-from-colliding
- http://javascriptweblog.wordpress.com/2010/12/07/namespacing-in-javascript/
- http://addyosmani.com/blog/essential-js-namespacing/
Now let’s talk about scope variables, we can have the same name as a global variable and local variable, but it is entirely separate because with the local variables ocreated and destroyed every time the function is executed, this is a little example of the msdn references:
One of the important things that if we don’t know maybe will cause a headache, is that JavaScript processes all variable declarations before executing any code, so we need to be careful where and when declare variables
Now we have this that in short words is a key that has reference to the own function where is invoked, so we can use this on global context, function context, since a object, constructor, DOM events, etc… let’s see one example in global context
now let’s see in an object
note that we need to create a function in an object property because if we don’t do it this, the key this, is reference to the global context
In some cases a method can be not used in functions that help them do their job because they do not have access to their properties, what i mean with this? let’s see an example,
As you can see the function is not the property of an object, this point to the global context, maybe we might think that this should be works because should be point the container function, but not, for do it this we need to create a variable that we can use as cache, for example:
Create and implement objects and methods
Javascript has three objects categories: Native Objects, Host Objects, and User-Defined Objects.
Native objects are those objects supplied by JavaScript. Examples of these are String, Number, Array, Image, Date, Math, etc.
Host objects are objects that are supplied to JavaScript by the browser environment. Examples of these are window, document, forms, etc.
And, user-defined objects are those that are defined by you, the programmer.
Examples:
References:
- http://www.sitepoint.com/oriented-programming-1-4/
- http://www.tutorialspoint.com/javascript/javascript_objects.htm
now let’s see prototypes, prototypes are properties of the function objects. Here is a example:
References:
- http://javascriptweblog.wordpress.com/2010/06/07/understanding-javascript-prototypes/
- http://www.packtpub.com/article/using-prototype-property-in-javascript
A method is a function too, although attached to an object, a method is just an object property that happens to be a function. like this: