Saturday, November 3, 2012

CheatSheet for Javascript language finer points, for-loop in Javascript

finer points, ...or indeed what you should know about the JavaScript Language right from the start, even.

http://bonsaiden.github.com/JavaScript-Garden/

Read when you have time, and want some leisure reading.

Learnt this, today:


http://bonsaiden.github.com/JavaScript-Garden/
Javascript Cheatsheet website
xxx();

function xxx() { //this function will fly to the top, document scope,
//even if function call is before this fn definition, still works.
}

var xxx = function () {} // if the fn call is before this fn def, will errormsg: xxx is 'undefined'

for namespacing purpose, function is the only struct that limits scope of its internal variables:
var Bill = {
xxx : function () {
// only function are scope boundary
// ...but only fly to here.
function aaa() {
// so this function aaa() won't be able to fly to the top...
}
(var x;)
for (a=0;a<2;a++) {
var x = 123; // this var will fly out of this for loop, as if belonging to
//the function xxx's scope. (as if declared as above line in parentheses)
}
 }

}

Bill.xxx()

Q. why need to wrap in $() the whole block?



















how to iterate over a list in javascript
http://ajaxian.com/archives/how-many-ways-can-you-iterate-over-an-array-in-javascript
THE CANONICAL WAY:
http://forums.asp.net/t/1040956.aspx/1
for(var i = 0; i < YourList.length; i++)
{
var yourObject = YourList[i];

//Do whatever you want.
}
http://www.openjs.com/articles/for_loop.php

More Optimized

var len=arr.length;
for(var i=0; i<len; i++) {
 var value = arr[i];
 alert(i =") "+value);
}







No comments:

Post a Comment