-
-
Save Marak/264247 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
// helper function for lazy initing objects | |
function jset( o,d ){ | |
if(typeof eval(o) == 'undefined'){ eval( o + ' = ' + d + ';' ); } | |
return true; | |
} | |
// jset() usage | |
jset ( 'drip' , '{}' ); | |
jset ( 'drip.value' , 42 ); | |
jset ( 'drip.URI' , 'google.com' ); | |
// Pseudo code, won't run | |
function jset( o , d , t){ | |
if( typeof eval( o ) == 'undefined' ){ | |
switch(t) | |
case 'numeric' : //numeric valication | |
case 'date' : // date validation / formating logic | |
case 'URI' : //URI validation logic | |
case 'route' : //route validation logic | |
if(all_validation_tests_pass) | |
eval( o + ' = ' + d + ';' ); | |
} | |
return true; | |
} | |
// jset() usage | |
jset ( 'drip' , '{}' ); | |
jset ( 'drip.value' , 42 , "numeric"); | |
jset ( 'drip.startDate' , "12/29/2009 03:46:00" , "date"); | |
jset ( 'drip.endDate' , "1/1/2010" , "date"); | |
jset ( 'drip.route' , "/blah/path/to/resource" , "route"); | |
jset ( 'drip.URI' , 'google.com', "URI" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment