2017-11-26

javascript programming

libraries

coffeescript syntax, classes

nodejs multi-purpose javascript implementation that works independent of browsers

expressjs web application framework

crel dom element creation helper

underscorejs higher order functions, collection processing utilities

module.js module system

browserify write browser javascript like node.js modules and generate one file for the browser

browser api documentation

semicolons

javascript semicolons

information encapsulation

to ease development and maintenance by making it easier to guess side-effects and execution flow with information encapsulation, and to avoid top-level namespace conflicts (trying to use two different bindings with the same name) and confusion created by unnecessary global variables, javascript has function local scope that can be used to create encapsulate bindings

when not using something like modulejs (modulejs only abstracts on the following), code can be wrapped inside a function like this

;(function () {
  // all the files code ...
})()

this is an anonymous-function application - a function without a name is defined and immediately called by specifying (). the ";" avoids syntax errors when semicolons are avoided or forgotten especially when files are concatenated at some point

or

someprefix.somemodule = (function () {
  // code ...
  return {
    exported_name: variable_name
    // ...
  }
})()

this creates an interface of accessible functions which excludes the inner utility functions and variables that may not be externally/generally applicable, in a scope where local bindings do not affect the top-level (if the var keyword is used consistently)

application parts should be available as objects in the root object, which is usually "window" in browsers. in nodejs it has a different name

window.{module-name}.{sub-module-name}.{variable_name}

bindings are then accessible with

module_name.sub_module_name.variable_name

and can be shortened locally like

var shortname = module_name.sub_module_name.variable_name

tags: programming start document guide pattern javascript computer