Skip to content

Instantly share code, notes, and snippets.

@shiawuen
Created March 6, 2012 02:15
Show Gist options
  • Save shiawuen/1982919 to your computer and use it in GitHub Desktop.
Save shiawuen/1982919 to your computer and use it in GitHub Desktop.
Can instance methods not be called from within other instance methods?
var goose = require('mongoose')
, db = goose.connect('mongodb://localhost/testmongo')
, Schema = goose.Schema
, sc = new Schema({
a: String,
b: Date
})
sc.methods.bbb = function() {
return this.b.getFullYear()
}
sc.methods.aaa = function() {
return this.a + this.bbb()
}
var M = db.model('sc', sc)
, m = new M({a: 'test', b: new Date()})
// Can instance methods not be called from within other instance methods?
// WORKS!
console.log(m.aaa());
@zimdo
Copy link

zimdo commented Mar 19, 2012

cool. thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment