Created
October 13, 2010 22:53
-
-
Save brianleroux/625120 to your computer and use it in GitHub Desktop.
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
function Person() { | |
// properties and validations | |
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 | |
timestamp(); | |
// callbacks | |
creating({ before:poundSalt, after:emailActivationCode }); | |
updating(); | |
deleting(); | |
// a private function to generate a unique salt for hashing the password, called in 'creating' callback | |
// testable therefore by the creating callback? | |
var poundSalt = function(obj) { | |
}; | |
// emails an activation code | |
var emailActivationCode = function(obj) { | |
}; | |
var forgotPassword = function(obj) { | |
}; | |
// public instance attributes | |
this.prototype = { | |
// activates the user account | |
get active() { | |
}, | |
set active() { | |
} | |
} | |
// views, beautiful custom finders | |
view('tags', { map:function(){}, reduce:function(){} }); | |
view('popular'); | |
}; |
I created a fork with some style changes. Also I noticed the views section. What exactly do they do?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I left work so I actually do not remember how I made it sort work but essentially it was some runtime recompilation. Yes: evil. But this is just a thought experiment.
Another way would be to create a magical methods() method that accepts an obj for mixing into the
__proto__
. Meh.The combinations of Proxy and Reflect make this sort of business pretty easy... I do hope those innovations make it into the language proper.