Skip to content

Instantly share code, notes, and snippets.

@matchew
Created February 16, 2015 20:40
Show Gist options
  • Save matchew/f9cae5c1b73cbec48c2c to your computer and use it in GitHub Desktop.
Save matchew/f9cae5c1b73cbec48c2c to your computer and use it in GitHub Desktop.
why undefined?
var Person = require('./person')
, bob = new Person('bob')
, express = require('express')
, app = express()
;
bob.sayName();
app.get('/person', bob.getName)
app.listen(3000, function() { console.log('listening...') });
module.exports = person
function person(name) { this.name = name; }
person.prototype.sayName = function() {
console.log('my name is ' + this.name);
};
person.prototype.getName = function(req, res) {
console.log('request has arrived');
res.send('my name is ' + this.name);
};
//////////////
// tty1
/////////////
$ node index.js
my name is bob
listening...
request has arrived
//////////////
// tty2
/////////////
$ curl 'localhost:3000/person'
my name is undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment