Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Narwhal and the Adventures of CommonJS


Published on

Published in: Technology
  • Be the first to comment

Narwhal and the Adventures of CommonJS

  1. 1. Narwhal and the Adventures of CommonJS Clinton R. Nixon
  2. 2. CommonJSpromises  to  be  a  standard  environment  that   will  let  JavaScript  code  use  the  same  APIs   with  different  interpreters
  3. 3. Why?JavaScript  is  simple  and  widely-­‐known.To  succeed,  server-­‐side  JavaScript  must  avoid  the  fate  of  Lisp.
  4. 4. CommonJS standardsModulesPackagesSystemBinaryFilesystemUnit  Testing
  5. 5. CommonJS implementationsNarwhal  (Rhino,  v8,  JSC)Flusspferd  (Spidermonkey/C++)node.js  (v8;  not  many  standards  or  proposals  implemented)v8cgi  (v8)GPSEE  (Spidermonkey/C)RingoJS  (Rhino;  was  Helma  NG)Perservere  (Rhino)SproutCore  (in-­‐browser)
  6. 6. Narwhalone  of  the  most  mature  CommonJS  implementations
  7. 7. NarwhalA  CommonJS  platform  or  implementationArguably  the  most  mature  implementationRuns  on  several  interpretersRhino  has  the  most  complete  implementationJavaScriptCore  works  well  on  MacsEasy  to  add  new  engines  if  youre  a  language  implementation  hacker
  8. 8. Why?You  can  use  it  todayRhino  makes  it  easy  to  build  off  Java  librariesLots  of  activity,  and  other  implementations  are  working  to  be  compatible  with  itBut  still  needs  lots  of  work
  9. 9. Narwhal packages package.jsonBased  on  the  CommonJS   local.json bin/package  standard lib/tusk  is  a  package  manager    foo.js src/sea  is  an  environment  manager jars/ packages/Every  project  is  a  package engines/ tests/    foo.tests.js
  10. 10. package.json{        "name":  "jake",        "author":  "Francisco  Tolmasky  <>",        "contributors":  [                "Tom  Robinson  (  <>"        ],        "description":  "A  build  system  for  CommonJS,  lifted  from  Rake",        "keywords":  [                "build",                "jake",                "rake",                "make"        ],        "version":  "0.2.1"}
  11. 11. ModulesEach  JS  file  under  lib/  is  a  moduleModules  are  executed  within  a  functionArguments  are  require,  exports,  and  moduleModules  return  exportsCore  concept  of  CommonJS
  12. 12. Module & package demonstration
  13. 13. Testing demonstration
  14. 14. Package management
  15. 15. sources.json{    "version":  2,    "includes":  ["­‐2.json"],    "sources":  {        "dice":  {            "type":  "github",            "user":  "crnixon",            "name":  "narwhal-­‐dice"        },        "caffeine":  {            "type":  "github",            "user":  "crnixon",            "name":  "narwhal-­‐caffeine"        }    }}
  16. 16. Important packagesjackjakejsdocsejsnitrobogart
  17. 17. Real apps I wrote
  18. 18. Questions and discussion  me  at  Clinton  R.  Nixon  <>