Skip to content

Instantly share code, notes, and snippets.

@chrismytton
Created February 17, 2010 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismytton/306910 to your computer and use it in GitHub Desktop.
Save chrismytton/306910 to your computer and use it in GitHub Desktop.
var calculator = {
add: function (a, b) {
return a + b
},
subtract: function (a, b) {
return a - b
},
multiply: function (a, b) {
return a * b
},
divide: function (a, b) {
return a / b
}
}
process.mixin(exports, calculator)
// Assuming that calc.js is in the same dir as this file
var calc = require('./calc')
// Now we can use the calc object to do calculations, joy!
var ten = calc.add(3, 7)
var two = calc.subtract(5, 3)
$ node hello.js
Hello World!
var sys = require('sys')
function sayHello (name) {
return 'Hello ' + name + '!'
}
sys.puts(sayHello('World'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment