-
-
Save creationix/625450 to your computer and use it in GitHub Desktop.
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() { | |
}; | |
} |
If you return an obj, then 'this' is pointless.
@isaacs only if you intend to use it as a constructor. If it's a function called by the framework with a custom scope, then this could hold meta functions.
I guess... just seems like a lot of magic for a small amount of style. Why not just use js as-is? Its not so hard.
I thought I was using javascript as-is. It's no more magic than Step.
'Its not so hard." sure comes off as a rather arrogant response to a non working psuedo dsl thought experiment!
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:
function Foo () {
// init
} << Bar << {
foo : function () { .. }
}
var f = new Foo()
f instanceof Bar // true
f instanceof Foo // true
f.foo()
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.
yeah I was trying to get rid of those
this
's ... so much visual entropy! there has to be a way to do this cleanly w/ today's syntax without resorting to backflips. Like the module pattern return statement but now things like email, etc are not publically accessible (tho maybe thats what we'd desire? I love fucking w/ my brain on these sorts of ideas.)view's are just couchdb views... tho I suppose it would map well to any doc db