Make the JavaScript Test Pass

Posted on Dot net Slackers See other posts from Dot net Slackers
Published on Fri, 18 Jun 2010 00:00:00 GMT Indexed on 2010/06/18 2:54 UTC
Read the original article Hit count: 281

Filed under:
Add code on the commented line: var f = function () { var value = // ??? return f.sum = (f.sum || 0) + value;} ... to make the following QUnit test pass: test("Running sum", function () { equals(f(3), 3); equals(f(3), 6); equals(f(4), 10); jQuery([1, 2, 3]).each(f); equals(f(0), 16); }); Possible Answer It's a goofy scenario, but one possible solution uses a technique you'll see frequently inside today's JavaScript libraries. First, we'll need to use the implicit arguments parameter inside...

Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.



Email this Article

© Dot net Slackers or respective owner