Book Image

Learning Dojo

By : Peter Svensson
Book Image

Learning Dojo

By: Peter Svensson

Overview of this book

<p>Dojo is a popular AJAX-specific open-source JavaScript framework for building powerful web applications. It provides a well conceived API and set of tools to assist you and fix the issues experienced in everyday web development. Your project size is no concern while using Dojo. It is the best scalable solution to all your size-related issues.<br /> <br />This book starts by giving you tips and tricks for programming with JavaScript. These tricks will help you with Dojo. With every chapter, you will learn advanced JavaScript techniques. You will learn to leverage Dojo for a clean web application architecture using JSON or XML.</p>
Table of Contents (13 chapters)
Learning Dojo
Credits
About the Author
About the Reviewer
Preface
Free Chapter
1
Introduction to Dojo

Intermediate Dojo functions


The following functions are related in:

The function dojo.filter takes two arguments: an array and a filtering function and returns an array. Suppose that you want to do the following:

function makeNewArray(arg_arr, ceiling)
{
var new_arr = [];
for(var i = 0; i < arg_arr.length; i++)
{
var element = arg_arr[i];
if (element > ceiling)
{
new_arr.push(element);
}
}
return new_arr;
}

The same code can be expressed like this using the filter function:

function makeNewArray(arg_arr, ceiling)
{
return dojo.filter(arg_arr, function(x){ return x > ceiling; })
}

What happened now? Most importantly, all intermediate index variables and temporary variables evaporated, reducing the risk for errors drastically.

In some more detail, dojo.filter applies the function argument on every element of the array. If the function returns true, dojo.filter will add the element to an invisible return value array. If it returns numerical zero it does not.

It will also coerce other...