WebFund 2013F Lecture 15: Difference between revisions
Created page with "==Notes== ===Assignment 3 Tips=== * Question 6 : Every time the user score changes, you can update the high score ** Cheating! It doesn’t have to be constantly updated in ..." |
No edit summary |
||
Line 1: | Line 1: | ||
The audio from the lecture given on November 11, 2013 is [http://homeostasis.scs.carleton.ca/~soma/webfund-2013f/lectures/comp2406-2013f-lec15-11Nov2013.m4a here]. | |||
==Notes== | ==Notes== | ||
Latest revision as of 18:01, 21 November 2013
The audio from the lecture given on November 11, 2013 is here.
Notes
Assignment 3 Tips
- Question 6 : Every time the user score changes, you can update the high score
- Cheating! It doesn’t have to be constantly updated in the background
- Or could use long poling
- Do ajax type call on the client
- On the server you would wait, set up a callback for when the high score changes
- Question 4:
- var container = $(‘#container’);
- returns a jQuery object
- //for the canvas:
- c = $(‘canvas’)[0];
- Anil will post something online about the problem errorsount.play();
- Need to use jQuery equivalent for the container.offsetLeft etc in function init()
- var container = $(‘#container’);
Going through tutorial 9
- In package.json there is a new line:
- "validator": "*"
- used for sanitizing user input
- req.session.player = sanitize(player).escape();
- sanitize sooner rather than later
- we only used this in the start function because this is the only user input that was taken
- "validator": "*"
- Want to send something back to the client?
- You can just use ‘send’ in node
- Complexity has been moved to the client code
- On the browser:
- If you want privacy, the only way you have it is doing it within functions!
- In public/javascripts/adventure.js
- Anonymous function is defined
- Prevents you from polluting the global file scope
- In public/javascripts/adventure.js
- In public/javascripts/adventure.js
- $.getJSON("/getContents", function(room)
- Get JSON object from server
- getContents is a function in routes/index.js
- this will return a page with an enoded JSON object
- jQuery will happily convert this
- $.getJSON("/getContents", function(room)
- var exits;
- doesn’t do anything
- If you want privacy, the only way you have it is doing it within functions!
$('.exits').remove(); room.roomExits.forEach(function(theExit) { $('#exitList').append( '<button type="button" id="' + theExit + '" class="btn btn-default exits">' + theExit + '</button>'); $('#'+theExit).on('click', function() { $.post("/doAction", {action: "move", room: theExit}); getRoom(); }); });
- Get rid of all of the exits
- Add button
- Add even handler
- When someone clicks on the mouse, it creates another post
- The value of the exit is coming from the argument to the function
- Array objects in JavaScript have a standard object called foreach
- Every webpage defines its own JavaScript scope
- Script is similar to include in C
- Implications of scripts
- You don’t know what code you’re incorporating
- It changes from minute to minute
- It runs in the same executions context of your code
- You have to deal with the DOM – it is global and everyone potentially has access to it
- What’s to say that code isn’t changing your code
- There are some things you can do, but it’s not easy