WebFund 2013F Lecture 15

From Soma-notes
Revision as of 23:42, 11 November 2013 by Sarahmathieson (talk | contribs) (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 ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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()

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
  • 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
      • $.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
    • var exits;
      • doesn’t do anything
	$('.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