Created
September 16, 2010 07:04
-
-
Save andyferra/582078 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
<html> | |
<head> | |
<script type="text/javascript"> | |
function SayChain(previous) { | |
var current = this; | |
this.previous = previous; | |
this.then = function(text) { | |
this.text = text; | |
this.next = new SayChain(this); | |
return this.next; | |
} | |
this.play = function(delay) { | |
if (this.previous) { | |
this.previous.play(delay); | |
} else { | |
this.execute(delay); | |
} | |
} | |
this.execute = function(delay) { | |
setTimeout(function() { | |
console.log(current.text); | |
if (current.next.text) { | |
current.next.execute(delay); | |
} | |
}, delay); | |
} | |
} | |
function say(text) { | |
return new SayChain().then(text); | |
} | |
say('apples').then('mud').then('pickles').then('elephants').then('sausuage').play(500); | |
function Query(previous) { | |
this.fragments = []; | |
this.where = function(sql) { | |
this.fragments.push( new WhereQueryFragment(sql) ); | |
return this; | |
} | |
this.all() { | |
} | |
this.build() { | |
} | |
} | |
function WhereQueryFragment() { | |
} | |
function User() { | |
} | |
User.where = function(sql) { | |
return new Query().where(sql); | |
} | |
User.where('name == "blaine"').order('created_at').all(); | |
function Sequence(callbacks) { | |
this.callbacks = callbacks; | |
this.run = function() { | |
} | |
} | |
new Sequence([ | |
function() { }, | |
function() { }, | |
function() { }, | |
function() { } | |
]).play(500); | |
</script> | |
</head> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment