Skip to content

Instantly share code, notes, and snippets.

@boundsj
Created July 20, 2012 19:31
Show Gist options
  • Save boundsj/3152737 to your computer and use it in GitHub Desktop.
Save boundsj/3152737 to your computer and use it in GitHub Desktop.
Node global, module, export exercise
var user1 = require('./user.js'),
user2 = require('./user.js'),
assert = require('assert');
// initialize the value in user1
user1.name("test");
// set it to another value in user2
user2.name("ohai");
// user1's value has been changed
assert.equal(user1.name(), "ohai", "oops");
// make two sep user prototypes
var userProto1 = new user1.User("grumpy");
var userProto2 = new user1.User("bumpy");
// the names of the two users are different, of course!
assert.notEqual(userProto1.name, userProto2.name, "oops");
var _name = "";
// getter & setter frankenstein!
// this will essentially be a global, singleton
exports.name = function(n) {
if (n !== "" & n !== undefined) { _name = n; }
return _name;
};
// this is a prototype that will maintain
// it's own state
exports.User = function(n) {
this.name = n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment