A Quick jQuery tutorial
Javascript Array.each
A simple function that can be used to iterate an array in JavaScript is Array.each a very simple implementation for this function is:
Array.prototype.each = function(callback){
for (var i = 0; i < this.length; i++){
callback(this[i]);
}
}
This function can be used as following:
var test = new Array(1, 2, 3, 4, 5, 6);
test.each(function(elem){
console.log(elem * elem);
});
You can test this function in Firefox with firebug. The example will not work in Internet explorer because console.log is not defined in IE.
JavaScript libraries I love most
JavaScript libraries has contributed to the evolution of web and helped greatly to move web2 sites. Also it makes the development of user front end and improvement of user experience more easy. The most loved libraries on the web, ordered by my preferences, are:
1- JQuery http://www.jquery.com: A very useful and easy library. It is used by a group of large sites and corporations like Mozilla and Microsoft. JQuery has a strong UI librairy found at http://ui.jquery.com.
2- Prototype http://www.prototypejs.org: Featuring a unique, easy-to-use toolkit for class-driven development and the nicest Ajax library around, Prototype is quickly becoming the codebase of choice for web application developers everywhere (prortype official site). It has a very powerful UI library based on it found at http://script.aculo.us/
Javascript Array.indexOf
The indexOf sometimes is extremely useful function that is used to get the index of an element in an array. This function is not implemented in Internet Explorer (IE). A simple implementation to this function can be as:
if(!Array.indexOf){
Array.prototype.indexOf = function(obj){
for(var i=0; i < this.length; i++){
if(this[i]==obj){
return i;
}
}
return -1;
}
}
Another advanced implementation is introduced by Mozilla here.