Created
December 11, 2012 04:53
-
-
Save Raynos/4255961 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 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