Created
February 16, 2015 20:40
-
-
Save matchew/f9cae5c1b73cbec48c2c to your computer and use it in GitHub Desktop.
why undefined?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...') }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////// | |
// 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