Week 4: javascript

Posted by Leroy on Oct 5, 2009 in Introduction into Client Technologies: HTML |

For week 4, I was pretty confident I’d be able to do the javascript assignment quickly. Having never really used JS, but being relatively experienced with C++, I felt at home with it instantly due to the the identical syntax, so the only thing I had to learn were some minor differences between the languages and the document object model, which turned out to be quite some work still, but only took me a short while to figure out with the internet to reference. All in all, I think it took me about an hour and a half to have the bug-free assignment done and I’m very pleased with that. the DOM is still a bit scary, but was easier to play with than I though it would be.

You can basically set the name and id tags of a div or a other tag, and address html elements, or groups of elements using those using getElementById or getElementByName which return objects for you to work with. the only real difference between JS and C/++ was with function declarations/implementations where you don’t need to specify a return type, nor do you need to specify the variable types, or even use the var statement for function arguments.

I’ll give an example:
First one is a function in JS

1
2
3
4
5
6
7
8
function PopulateOptions(options, max)
{
	var i;
	for(i = 0; i < max; i++)
	{
		AddOption(options, i);
	}
}

and the same function rewritten in C/++

1
2
3
4
5
6
7
8
void PopulateOptions(OptionsList* options, int max)
{
	int i;
	for(i = 0; i < max; i++)
	{
		AddOption(options, i);
	}
}

As you can see, nothing dramatic, pretty easy to understand and read!

Once again, pretty easy homework to do ; ]

Tags: , ,

Comments are closed.

Copyright © 2010   Art & Technology   @ NHTV All rights reserved. Theme by Laptop Geek.