WebFund 2013F Lecture 3: Difference between revisions

From Soma-notes
No edit summary
No edit summary
 
Line 17: Line 17:
** prototypes versus classes
** prototypes versus classes
** JSON notation
** JSON notation
==notes==
September 16
* history of JS
* REPL
* quirks
** equality
** numbers
** comments
** globals
* browser vs serverJS
* symbols and assignment
* object
[[history of JS]]
* nothing to do with java
* created over the course of a few weeks (~10 days) to script webpages
** got into Netscape 2 in the late 90's
* not great, but got there at the right time, standardized
** premature, rough draft, mistakes were made
* some amazing ideas, some so good that let you get around the rest of the issues
* don't think about C, don't think about Java, think about LISP
** 2nd oldest language (goes back to late 1950's
** modern variants - scheme (cleaner version)
** LISP = LiSTProcessing
*** at the time, it was all about symbol programming
==REPL==
* Model
* Read
* Eval 
basically evaluating all the time
* Print
** output of print can almost always be sent to read
** that means the data structure is in a format that can be read in
* Loop
* can do things incrementally, iteratively
* no compilation
** no compile time errors, only ~runtime errors
* loosely typed - generally not statically typed
** refers to the nature of the symbols you manipulate
** in C x=5;
*** is storing the value of 5 somewhere in memory
*** int, double, short, char... etc
* in javascript x=5
*** not ambiguous
*** y=x+5 won't give you an error until code is executed
* can write smaller programs that are more expressive
* some people hate javascript because of the browser
** DOM - Document Object Model
*** ugly, painful, inconsistent
* quirks
** write code to work on one browser, doesn't work properly on another
** less pain than before, but still a factor
** mobile stuff still being standardized
==quirk #1==
f = function(a,b) {
    x=7;
}
* wouldn't see this in something like C,
* in JavaScript it becomes a global variable
* have to specify that it is a local variable
* all symbols are seen globally by everyone else because there is no linker
* don't pollute global namespace
==quirk #2==
* comments can only be //, can't block comment
==quirk #3==
* equality operator is ===, for comparisons
* == does a shallow comparison
==quirk #4==
* no integer type
* can't do integer division without explicit truncates etc
* have to be conscious that you are using floats when doing numeric computations
var x = {
color "red";
model "unknown";
};
//this is an object, object notation
* property and value
* no classes
x.make = "?"
var x = {
make"?";
color "red";
model "unknown";
prototype : car;
crash.function(velocity); // method
};
* x.prototype is the same as car
* x.prototype.make="Tesla";
** there is inheritance -- but it's weird
*** prototype-based inheritance
**** prototype : car;
*** x.model
* symbols can refer to any value, have no type
* browser vs server JS

Latest revision as of 21:24, 8 November 2013

Audio from the lecture given on September 16, 2013 is available here.

Readings:

  • Chapters 1-3, JavaScript: The Good Parts
  • Chapters 1-2, Learning Node

Topics covered:

  • REPL (read-eval-print loop)
  • JavaScript quirks
    • Numbers are all floats
    • ambiguous comment characters
    • === equality
    • undeclared variables have global scope
  • JavaScript objects and variables
    • loose typing
    • scoping
    • prototypes versus classes
    • JSON notation


notes

September 16

  • history of JS
  • REPL
  • quirks
    • equality
    • numbers
    • comments
    • globals
  • browser vs serverJS
  • symbols and assignment
  • object

history of JS

  • nothing to do with java
  • created over the course of a few weeks (~10 days) to script webpages
    • got into Netscape 2 in the late 90's
  • not great, but got there at the right time, standardized
    • premature, rough draft, mistakes were made
  • some amazing ideas, some so good that let you get around the rest of the issues
  • don't think about C, don't think about Java, think about LISP
    • 2nd oldest language (goes back to late 1950's
    • modern variants - scheme (cleaner version)
    • LISP = LiSTProcessing
      • at the time, it was all about symbol programming

REPL

  • Model
  • Read
  • Eval
basically evaluating all the time
  • Print
    • output of print can almost always be sent to read
    • that means the data structure is in a format that can be read in
  • Loop
  • can do things incrementally, iteratively
  • no compilation
    • no compile time errors, only ~runtime errors
  • loosely typed - generally not statically typed
    • refers to the nature of the symbols you manipulate
    • in C x=5;
      • is storing the value of 5 somewhere in memory
      • int, double, short, char... etc
  • in javascript x=5
      • not ambiguous
      • y=x+5 won't give you an error until code is executed
  • can write smaller programs that are more expressive
  • some people hate javascript because of the browser
    • DOM - Document Object Model
      • ugly, painful, inconsistent
  • quirks
    • write code to work on one browser, doesn't work properly on another
    • less pain than before, but still a factor
    • mobile stuff still being standardized

quirk #1

f = function(a,b) {
    x=7;
}
  • wouldn't see this in something like C,
  • in JavaScript it becomes a global variable
  • have to specify that it is a local variable
  • all symbols are seen globally by everyone else because there is no linker
  • don't pollute global namespace

quirk #2

  • comments can only be //, can't block comment

quirk #3

  • equality operator is ===, for comparisons
  • == does a shallow comparison

quirk #4

  • no integer type
  • can't do integer division without explicit truncates etc
  • have to be conscious that you are using floats when doing numeric computations
var x = {
	color "red";
	model "unknown";
	};
	//this is an object, object notation
  • property and value
  • no classes
x.make = "?"
var x = {
	make"?";
	color "red";
	model "unknown";
	prototype : car;
	crash.function(velocity); // method
	};
  • x.prototype is the same as car
  • x.prototype.make="Tesla";
    • there is inheritance -- but it's weird
      • prototype-based inheritance
        • prototype : car;
      • x.model
  • symbols can refer to any value, have no type
  • browser vs server JS