Focus: http://www.javascriptkit.com/
Create an object:
var car = new Object ();
Car.colour = ' red ';
Car.wheels = 4;
Car.hubcaps = ' spinning ';
Car.age = 4;
The same can acchieved with:
var car = {
Colour: ' Red ',
Wheels:4,
Hubcaps: ' Spinning ',
Age:4
}
Note: But what happens when do you use invalidUserInSession
? The main gotcha in this notation is IE. Never ever leave a trailing comma before the closing curly brace or you'll be in trouble.
var moviesthatneedbetterwriters = new Array (
' Transformers ', ' Transformers2 ', ' Avatar ', ' Indiana Jones 4 '
);
var moviesthatneedbetterwriters = [
' Transformers ', ' Transformers2 ', ' Avatar ', ' Indiana Jones 4 '
];
Sort the data in an array, using the sort () directly, refer to the article: http://www.javascriptkit.com/javatutors/arraysort.shtml
Notice that the can not use sort () on a number array because it sorts lexically (lexical aspect).
var numbers = [23, 342, 87, 145];
Numbers.sort (function (A, b) {return a B;}); Ascending, ascending
Numbers.sort (function (A, b) {return b-a;}); /descending, Descending
Math.max (123, 3, 2, 433, 4);//math.max () return the largest number form a list of parameters
Because This tests for numbers and returns the largest one, you can use it to test for browser support of Cetain Properti Es.
var scrolltop = Math.max (
Doc.documentElment.scrollTop,
Doc.body.scrollTop
);
[Label] [JavaScript] seven JavaScript tips