Skip to content

Instantly share code, notes, and snippets.

@andyferra
Created September 16, 2010 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyferra/582078 to your computer and use it in GitHub Desktop.
Save andyferra/582078 to your computer and use it in GitHub Desktop.
<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