Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created December 11, 2012 04:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/4255961 to your computer and use it in GitHub Desktop.
Save Raynos/4255961 to your computer and use it in GitHub Desktop.
function Base(text) {
return function () {
return text
}
}
function Derived(source, prefix) {
var text = Base(source)
return function () {
return prefix + text() + prefix
}
}
function Derived2(source, prefix, color) {
var text = Derived(source, prefix)
return function () {
return color + text()
}
}
var d = Derived('foo', '!'),
d2 = Derived2('bar', '!', 'red'),
assert = require('assert');
assert.equal( d(), '!foo!' );
assert.equal( d2(), 'red!bar!' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment