Skip to content
Browse files

Added closure example

  • Loading branch information...
1 parent 6d1503b commit 2753e754ff556e16ff535d86f416e3d4f9af780b @jakubmal jakubmal committed Apr 13, 2012
Showing with 17 additions and 0 deletions.
  1. +17 −0 tests/app/functions.js
View
17 tests/app/functions.js
@@ -69,5 +69,22 @@ define([ 'use!underscore' ], function(_) {
expect(fn(curryMe2, 12, 3)(5)).to.be(20);
expect(fn(curryMe2, 12, 3, 5)()).to.be(20);
});
+
+ it('you should be able to use closure', function () {
+ var arr = [54, 2345, 32, 45, 127];
+ var doSomeStuff;
+
+ fn = function (vals) {
+ // define a function for fn so that the following will pass
+ };
+
+ doSomeStuff = function (x) { console.log(x); return x * x; };
+
+ var funcs = fn(arr);
+ expect(funcs).to.have.length(5);
+ for (var i = funcs.length - 1; i >= 0; i--) {
+ expect(funcs[i]()).to.be(doSomeStuff(arr[i]));
+ };
+ });
});
});

0 comments on commit 2753e75

Please sign in to comment.
Something went wrong with that request. Please try again.