55
CommonJS JavaScript Everywhere Kevin Dangoor, Kris Kowal, Tom Robinson jsconf.eu — 2009-11-07

CommonJS: JavaScript Everywhere

Embed Size (px)

DESCRIPTION

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.

Citation preview

Page 1: CommonJS: JavaScript Everywhere

CommonJSJavaScript Everywhere

Kevin Dangoor, Kris Kowal, Tom Robinsonjsconf.eu — 2009-11-07

Page 2: CommonJS: JavaScript Everywhere

Kevin DangoorMozilla Labs

Page 3: CommonJS: JavaScript Everywhere

Kris KowalFastSoft, Inc.

Page 4: CommonJS: JavaScript Everywhere

problem + CommonJS = solution

Page 5: CommonJS: JavaScript Everywhere
Page 6: CommonJS: JavaScript Everywhere

There are many ways to do these things

in JavaScript.

There is no standard way to do these things

in JavaScript.

Page 7: CommonJS: JavaScript Everywhere
Page 8: CommonJS: JavaScript Everywhere
Page 9: CommonJS: JavaScript Everywhere
Page 10: CommonJS: JavaScript Everywhere
Page 11: CommonJS: JavaScript Everywhere
Page 12: CommonJS: JavaScript Everywhere
Page 13: CommonJS: JavaScript Everywhere
Page 14: CommonJS: JavaScript Everywhere
Page 15: CommonJS: JavaScript Everywhere
Page 16: CommonJS: JavaScript Everywhere
Page 17: CommonJS: JavaScript Everywhere
Page 18: CommonJS: JavaScript Everywhere
Page 19: CommonJS: JavaScript Everywhere
Page 20: CommonJS: JavaScript Everywhere
Page 21: CommonJS: JavaScript Everywhere
Page 22: CommonJS: JavaScript Everywhere
Page 23: CommonJS: JavaScript Everywhere
Page 24: CommonJS: JavaScript Everywhere
Page 25: CommonJS: JavaScript Everywhere
Page 26: CommonJS: JavaScript Everywhere
Page 27: CommonJS: JavaScript Everywhere
Page 28: CommonJS: JavaScript Everywhere
Page 29: CommonJS: JavaScript Everywhere
Page 30: CommonJS: JavaScript Everywhere
Page 31: CommonJS: JavaScript Everywhere
Page 32: CommonJS: JavaScript Everywhere
Page 33: CommonJS: JavaScript Everywhere
Page 34: CommonJS: JavaScript Everywhere
Page 35: CommonJS: JavaScript Everywhere
Page 36: CommonJS: JavaScript Everywhere
Page 37: CommonJS: JavaScript Everywhere
Page 38: CommonJS: JavaScript Everywhere
Page 39: CommonJS: JavaScript Everywhere
Page 40: CommonJS: JavaScript Everywhere
Page 41: CommonJS: JavaScript Everywhere
Page 42: CommonJS: JavaScript Everywhere
Page 43: CommonJS: JavaScript Everywhere
Page 44: CommonJS: JavaScript Everywhere
Page 45: CommonJS: JavaScript Everywhere
Page 46: CommonJS: JavaScript Everywhere
Page 47: CommonJS: JavaScript Everywhere
Page 48: CommonJS: JavaScript Everywhere
Page 49: CommonJS: JavaScript Everywhere
Page 50: CommonJS: JavaScript Everywhere
Page 51: CommonJS: JavaScript Everywhere
Page 52: CommonJS: JavaScript Everywhere

import jsonimport hashlibimport sys

def main(args): raw_data = open(args[1]).read() strings = json.loads(raw_data) h = hashlib.md5() for s in strings: h.update(s) print h.hexdigest()

if __name__ == "__main__": main(sys.argv)

var file = require("file");var system = require("system");var md5 = require("md5");

exports.main = function(args) { var rawData = file.read(args[1]); var strings = JSON.parse(rawData); var hashed = md5.hash(strings.join("")); print(hashed.toString(16));};

if (module.id == require.main) { exports.main(system.args);}

Page 53: CommonJS: JavaScript Everywhere

bash-3.2$ python simple.py testdata.json 900150983cd24fb0d6963f7d28e17f72bash-3.2$ js simple.js testdata.json 900150983cd24fb0d6963f7d28e17f72

http://www.codinghorror.com/blog/archives/000818.html

Page 54: CommonJS: JavaScript Everywhere

CommonJS

http://commonjs.org/You can make a difference!

Page 55: CommonJS: JavaScript Everywhere

Q&A

http://commonjs.org/