0

I'm currently building a project at work, requiring me pulling in an array of objects, and pinning them on a map.

I'm storing my markers in an array, so that I can reset the map when a user searches for different criteria.
This was all working perfectly until I included Smart Client.

I'm not very familiar with Smart Client, but it seems to be adding an Array class object to my array, thus breaking my for loop.

var wrap = (function() {
    var arr;

    function myFunc(a) {
        for (var i in arr) 
            arr[i] = null; //doing this to set all markers to null
        }
        arr = [];
        for (var i in a) {
            arr.push(a[i]);
        }
    }

    return {
        doSomething: function(a) { myFunc(a); }
    }
})();
wrap.doSomething([1,2,3,4]);
wrap.doSomething([1,2,3,4]);

This gives me a TypeError: undefined is not a function error.

smartclient library, smart gwt. I have included the following files.

<script>var isomorphicDir = "/smartclient/isomorphic/";</script>
<script src="/gmap/smartclient/isomorphic/system/modules/ISC_Core.js"></script>
<script src="/smartclient/isomorphic/system/modules/ISC_Foundation.js"></script>
<script src="/smartclient/isomorphic/system/modules/ISC_Containers.js"></script>
<script src="/smartclient/isomorphic/system/modules/ISC_Grids.js"></script>
<script src="/smartclient/isomorphic/system/modules/ISC_Forms.js"></script>
<script src="/smartclient/isomorphic/system/modules/ISC_DataBinding.js"></script>
<script src="/smartclient/isomorphic/skins/Enterprise/load_skin.js"></script>

regardless of initialising these files before or after my own js, I still get the same error.

I am open to viable alternatives that provider a better/cleaner solution to producing large, dynamically sortable and groupable tables, in javascript.

hamhut1066
  • 406
  • 3
  • 13

1 Answers1

1

I'm not familiar with Smart Client either, but there is a problem in your code that should explain the TypeError. The wrap variable is set to the return value of the IIFE (function that starts on line 1). Since it doesn't return anything, wrap will be undefined. doSomething is simply a function local to the IIFE, so you can't call it outside of it.

In addition, there seems to be a problem with the curly braces in your sample code? There is one too many { compared to }...

Assuming you correct the issue with the curly braces, you can get rid of it by adding the following at the end of the wrap IIFE (after the last for loop):

return {
    doSomething: doSomething
};

That should assign an object to the wrap variable,

eireksten
  • 46
  • 3
  • thanks, I have actually implemented that in my code, I just got too caught up trying to get the formatting right using the SO input field. – hamhut1066 Jul 03 '14 at 16:40