title: Why do I get "Illegal invocation" of this object?
body: <p>Why do I get "<strong>Uncaught TypeError: Illegal invocation</strong>" when I post this functions returned object into an ajax post:</p>
  
  <pre><code>base.serialize = function()
  {
  var data
    , depth = 0;
  
      step = function(level, depth)
      {       
          var array  = [ ]
            , items = level.children("li");
  
              items.each(function()
              {
                  var   li   = $(this)
                      , item = $.extend({}, li.data())
                      , sub  = li.children("ol");
  
                      if (sub.length)
                      {
                          item.children = step(sub, depth + 1);
                      }
  
                  array.push(item);
              });
  
          return array;
      }
  
  data = step(base.$el, depth);
  
  return data;
  };
  </code></pre>
  
  <p>What I'm trying to do is to convert an HTML tree with data values to an array, to save sort order to database:</p>
  
  <pre><code>/*
   * ------------------------------------------------------
   *  Liveflex Treeview
   * ------------------------------------------------------
   */
  var tree = $(".dd-list").liveflex_treeview({
        handle        : 'div.dd-handle'
      , opencollapse  : '.opencollapse'
      , itemMoved     : function(e)
                      {
                          var sort_array = e.serialize();
  
                              // Save order
                              $.post('/url_fetch/sort_posts', { 'sort_array' : sort_array }, function(data)
                              {
                                  console.log('Data:' + data);
                              });
                      }
  });
  </code></pre>