-
-
Save creationix/625450 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function Person() { | |
// properties and validations | |
this.attr( | |
{ id: Number, unique: true, nullable: false }, | |
{ email: String, unique: true, nullable: false, min: 1, max: 55, format: '[a-b]' }, | |
{ salt: String }, | |
{ pswd: String }, | |
{ active: Boolean, init: false }, | |
{ tags: Array } | |
); | |
// helpful property declarations | |
this.timestamp(); | |
// callbacks | |
this.creating({ before: poundSalt, after: emailActivationCode }); | |
this.updating(); | |
this.deleting(); | |
// a private function to generate a unique salt for hashing the password, called in 'creating' callback | |
// testable therefore by the creating callback? | |
function poundSalt(obj) { | |
} | |
// emails an activation code | |
function emailActivationCode(obj) { | |
} | |
function forgotPassword(obj) { | |
} | |
// views, beautiful custom finders | |
this.view('tags', { map: function () {}, reduce: function () {} }); | |
this.view('popular'); | |
// public instance attributes | |
return { | |
// activates the user account | |
get active() { | |
}, | |
set active() { | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, not my intent to be arrogant, or overly critical of a sketch. Just that I have seen a lot of effort spent (by myself and others) on coding pattern non-problems in the past, and eventually came to the conclusion that just using ctor/prototype/new, in the standard way, while not the most pretty, is the least clever and surprising, and the easiest for a newcomer to jump into.
Yes, this is lovely:
and with the hooks JavaScript gives you into the casting process with
valueOf
, it's entirely doable. (This is an extreme example, to be sure.) While lovely, and I'm sure it'd be fun to spend a saturday implementing it, it's not terribly useful.Not that all sketches need to be diagrams. Some sketches can just be doodles, and that's perfectly ok. And occasionally something really neat comes out of the exploration.