Tuesday, February 2, 2010

How do you create a new object in JavaScript?

In order to generate dynamic content, JSP provides for creating, modifying and interacting with Java objects. The implicit objects like page, config, request, etc are called so because their availability in the in JSP page is automatic.
Also, along with using constructor functions (e.g. var mything = new myObject();), you can use Object Initializers to create objects in JSP.
E.g:
var myCar = {color:"white",wheels:4,engine:{cylinders:4,size:2.2}};

How to create arrays in JavaScript? 

Although you can create the arrays using ‘new’ (var myArray = new myArray[10];), it is recommended that you create it in the following way: var myArray = [];
You don't need to tell Javascript how many items to size the Array for. Javascript automatically increases the size of the Array as needed

0 Comments: