Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

NY Standup 5/11/2011: Chrome Frame for all my subjects!

Ask for Help

“How can we expect in Jasmine that a jQuery dialog has closed?”

The dialog animates out (asynchronously, of course), and it’s hard to have a test pass when it successfully disappears.

“In Javascript, How can we create an array of n empty arrays?”

One attempt, (new Array(n)).map(function() { return [] }) failed, because new Array(n) creates an array, n elements long, full of undefined. As it turns out, map() skips undefined in an array.

[Correction: new Array(n) creates an array which says its length is n, but which doesn’t have any elements, not even undefined. The following does map over the undefined elements (for n=3), but isn’t very useful to us.

[undefined, undefined, undefined].map(function() { return [] })

Thanks to John Pignata for pointing that out.]

Interesting Things

  • The latest version of Chrome Frame for Internet Explorer doesn’t require admin rights to install.

  1. John Pignata says:

    1) Jasmine’s mock clock might come in handy here – trigger the event, jasmine.Clock.tick() whatever number of milliseconds it takes for the dialog to be safely gone and then check for it.

    2) I’m not sure what the utility of the Array constructor’s arrayLength parameter is since it doesn’t even create elements at the given number of positions but only (ostensibly erroneously) sets the length.

    You could always do something like this:

    var n=10, arr=[];
    for (i = 0; i < n; i++) arr.push([]); Or if you’re lucky enough to be using Underscore.js in your project: var arr = []; _(10).times(function () { arr.push([]) });

  2. Peter Jaros says:

    1) I should have mentioned: mockClock doesn’t work here. jQuery may be using the browser’s native animation frame support, which mockClock doesn’t handle.

    2) Iiiinteresting. Yes, it seems that `new Array(n)` is pretty much useless.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *