WebFund 2016W Lecture 6: Difference between revisions

From Soma-notes
Zero (talk | contribs)
m Typo.
Zero (talk | contribs)
Added more in-class notes.
Line 25: Line 25:
  - methods
  - methods
  - constructors with new
  - constructors with new
  - apply
  - call/apply
- functions in global scope
 
* form demo!
 
------------------
 
If a function starts with a capital letter, it is an object
constructor that you call with new.
- why?  because it keeps JavaScript programmers sort of sane
 
if (x.a) { blah}    instead do
 
if (x.hasOwnProperty(a) && x.a) better, but
 
if (hasOwnProperty.call(x,a) && x.a) is even better
 
Why not tinywebserver?
 
* templates: otherwise, have to manually generate web pages using
  variable data
* routing: otherwise, you'll be using regexp's to match each
  incoming URL and then call the right function
 
</pre>
</pre>

Revision as of 20:52, 26 January 2016

Notes

In-class Notes

Lecture #6
---------

PLAN
* Assignment 2
  - aliases
  - headers
  - other clarifications?

* Objects
  - associative hashes with inheritance
  - prototypes using Object.create
  - "global" object
  - "Object" object
  - Object.prototype
  - hasOwnProperty and Object.hasOwnProperty

* Function calling and "this"
 - functions in regular scope
 - methods
 - constructors with new
 - call/apply
 - functions in global scope

* form demo!

------------------

If a function starts with a capital letter, it is an object
constructor that you call with new.
 - why?  because it keeps JavaScript programmers sort of sane

if (x.a) { blah}     instead do 

if (x.hasOwnProperty(a) && x.a) better, but

if (hasOwnProperty.call(x,a) && x.a) is even better

Why not tinywebserver?

* templates: otherwise, have to manually generate web pages using
  variable data
* routing: otherwise, you'll be using regexp's to match each 
  incoming URL and then call the right function