Object-Oriented JavaScript by Stoyan Stefanov

Object-Oriented JavaScript

5.4/102 min read

8/29/17

  • Objects are key value pairs, values can be any type, passed by reference, undefined for properties that are undefined

  • A function inside an object is called a method

  • Polymorphism: same name but different behavior; different method

  • Keyword this is set to the object or function we are calling

  • Instanceof: checks prototype

  • Wrapping JavaScript in function block creates a closure and avoids potential name clashes between modules and libraries

  • JavaScript is loosly typed, define without specifying type

  • No destructors in JavaScript

  • Graceful degradation: providing alternate version of functionality to ensure the product is usable, you start with modern browsers

  • Progressive enhancement: establish basic user experience and build in more advanced functionality

  • Optimize assets/resources: fewer HTTP requests, use Content Delivery Network, add an Expires header, put CSS on top, scripts on bottom, JavaScript and CSS external, minify JavaScript, avoid redirects, remove duplicate scripts, host assets on a different domain

  • Decrease page load: minimize images, combine JavaScript files, combine CSS files

  • Standards: more stable web, reduce development and maintenance time, backward capabilities, increase search engine success, common knowledge

  • CORS: cross-origin resource sharing, allows restricted resources to be requested from another domain

  • Undefined: value of variable was undefined, type is undefined

  • Null: empty or non-existant value, primative value, null == undefined

  • Object equality: primitives by value, objects compared by reference

  • 'false' is true because its a string greater than 0

  • Currying: partial invocation of a function

  • Window is a global object that holds global variables, functions, and location

  • Document is under window: window.document === document

  • Reflow: change the size or position of an element and everything else moves

  • Repaint: change the look without changing the size or shape

  • Use semantic tags for SEO, accessibility

  • Use anonymous functions because no name is needed or only used once