Difference between revisions of "WebFund 2015W Lecture 10"

From Soma-notes
Jump to navigation Jump to search
(Created page with "==Resources== * [http://homeostasis.scs.carleton.ca/~soma/webfund-2015w/code/notes-demo.zip notes-demo code] ==Video== The video from the lecture given on February 4, 2015 ...")
 
Line 8: Line 8:


==Notes==
==Notes==
===CORRECTION===
In lecture we saw that we could break notes-demo by giving <tt>hasOwnProperty</tt> as a username.  This error is because the following code in the login post handler is incorrect:
<source lang="javascript">
    if (!userNotes[username]) {
userNotes[username] = [];
    }
</source>
This code should instead say:
<source lang="javascript">
  if (!userNotes.hasOwnProperty(username)) {
      userNotes[username] = [];
  }
</source>
If you are treating a JavaScript object as an associative array you must explicitly check whether a given key value (property) is present using the hasOwnProperty() method inherited by every object.
Note you can create an object x with no prototype by doing the following:

Revision as of 13:38, 4 February 2015

Resources


Video

The video from the lecture given on February 4, 2015 is available now as an MP4.

Notes

CORRECTION

In lecture we saw that we could break notes-demo by giving hasOwnProperty as a username. This error is because the following code in the login post handler is incorrect:

    if (!userNotes[username]) {
	userNotes[username] = [];
    }

This code should instead say:

   if (!userNotes.hasOwnProperty(username)) {
       userNotes[username] = [];
   }

If you are treating a JavaScript object as an associative array you must explicitly check whether a given key value (property) is present using the hasOwnProperty() method inherited by every object.

Note you can create an object x with no prototype by doing the following: