Upload
kris-kowal
View
5.576
Download
3
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
CommonJSJavaScript Everywhere
Kevin Dangoor, Kris Kowal, Tom Robinsonjsconf.eu — 2009-11-07
Kevin DangoorMozilla Labs
Kris KowalFastSoft, Inc.
problem + CommonJS = solution
There are many ways to do these things
in JavaScript.
There is no standard way to do these things
in JavaScript.
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);}
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