-
Notifications
You must be signed in to change notification settings - Fork 0
Homeworkmeeting29 03 2011
Back to Homework
Ex 1
<script>
function test() {
var x = 3;
try { throw 5; }
catch (x) {}
alert(x);
}
test();
</script>
a) Run the script above in your favorite browser. What is the result ?
b) Run the same script in IE (you did not use IE the first time, did you ;-)
What’s going on here ??? If you got identical results you might say this is a stupid question.
Ex 2
<script>
var hello = "Hello World";
setTimeout(alert, 5000, hello);
</script>
a) Run the script in your favorite browser. What is the result ?
b) Run the same script in IE
c) What can we do instead to avoid different setTimeout implementations in the browsers ?
Ex 3
<script>
function getAgeInYears() {
return
{
helge: 28,
anders: 56
};
}
alert(getAgeInYears().anders);
</script>
What is returned ? Should return : "Younger than Helge !"
Ex 4
Your boss wants you to create a javscript function that traverses a object tree structure, i.e.:
var myObject = {
'name' : 'anders',
'age' : 56,
'languages' : ['norwegian', 'sami'],
'contactMethods' : {
'pstn' : '1111',
'isdn' : '2222',
'fax' : '3333'
}
};
The name of the function/method shall be "traverse". Display all objects in the traversed structure.
Ex 5
If not already covered in 4, make it possible to supply a function that can be applied on each of the objects while traversing.
The traverse function may then be reused for search, displaying etc.
Ex 6
The data contained in myObject from ex 4-5 is fetched from a central server asyncronosly.
Implement a function that fetches the myObject data asynchronosly and calls the traverse function after the data is returned.
In order to test this function, you may simulate the server side by a javascript function, i.e:
getDataForUser(name, myCallbackFunction)
which calls the myCallBackFunction after a few seconds with the myObject data as argument.
Include 3-4 name objects and make sure it returns the objects that corresponds to the name parameter.
Ex 7
If not already covered, make sure that all functions/methods from ex 6 are implemented in a separate "namespace" called CAPRICA.
Ex 8
If not already covered, make sure that the function in ex 6-7 can run several instances "simultanously", meaning that it is possible to start several requests before data is returned from the server.
Verify that the objects are returned to the "correct" requester instance.
Good luck !