CommonJS: JavaScript Everywhere

6,472 views

Published on

JavaScript is an enormously popular programming language, because of its unique place as the programming language of the web. Outside of that domain, JS is barely a blip compared to other dynamic languages like Python and Ruby. Outside of the browser, JavaScript is lacking something critical: a significant standard library. Thanks to a powerful standard library and a common module system, sophisticated applications can be written in Python and run unchanged on Windows, Mac and Linux and even across different interpreters including Jython and IronPython. The CommonJS project (formerly ServerJS) is building up a standard library API to give privileged JavaScript applications this same kind of interop. Imagine a server-side webapp that runs equally well in Rhino, SpiderMonkey and v8. We're getting there. Even better, those apps can easily share modules between the browser and the server, which is something you don't get in other languages. In this talk, I'll provide quick background on the project and demos of several implementations of the emerging standard, including how CommonJS impacts Mozilla's Jetpack and Bespin projects.

0 Comments
13 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,472
On SlideShare
0
From Embeds
0
Number of Embeds
2,259
Actions
Shares
0
Downloads
91
Comments
0
Likes
13
Embeds 0
No embeds

No notes for slide

CommonJS: JavaScript Everywhere

  1. 1. CommonJS JavaScript Everywhere Kevin Dangoor, Kris Kowal, Tom Robinson jsconf.eu — 2009-11-07
  2. 2. Kevin Dangoor Mozilla Labs
  3. 3. Kris Kowal FastSoft, Inc.
  4. 4. problem + CommonJS = solution
  5. 5. There are many ways to do these things in JavaScript. There is no standard way to do these things in JavaScript.
  6. 6. import json import hashlib var file = require("file"); import sys var system = require("system"); var md5 = require("md5"); def main(args): raw_data = open(args[1]).read() exports.main = function(args) { strings = json.loads(raw_data) var rawData = file.read(args[1]); h = hashlib.md5() var strings = JSON.parse(rawData); var hashed = md5.hash(strings.join("")); for s in strings: print(hashed.toString(16)); h.update(s) }; print h.hexdigest() if (module.id == require.main) { exports.main(system.args); if __name__ == "__main__": } main(sys.argv)
  7. 7. bash-3.2$ python simple.py testdata.json 900150983cd24fb0d6963f7d28e17f72 bash-3.2$ js simple.js testdata.json 900150983cd24fb0d6963f7d28e17f72 http://www.codinghorror.com/blog/archives/000818.html
  8. 8. CommonJS You can make a difference! http://commonjs.org/
  9. 9. Q&A http://commonjs.org/

×