Difference between revisions of "WebFund 2015W Lecture 10"

From Soma-notes
Jump to navigation Jump to search
Line 9: Line 9:
==Notes==
==Notes==


===CORRECTION===
===CORRECTION regarding hasOwnProperty()===


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:
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:
Line 30: Line 30:


Note you can create an object x with no prototype by doing the following:
Note you can create an object x with no prototype by doing the following:
<pre>
  x = Object.create(null);
</pre>
However, this is not normally done.  Indeed, even if you use a JSON parser objects will have a non-null prototype.
Thus, use hasOwnProperty()!

Revision as of 13:45, 4 February 2015

Resources


Video

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

Notes

CORRECTION regarding hasOwnProperty()

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:

  x = Object.create(null);

However, this is not normally done. Indeed, even if you use a JSON parser objects will have a non-null prototype.

Thus, use hasOwnProperty()!