Finding a variables type and the methods attached.

Finding a variables type and the methods attached.

dneedlesdneedles Posts: 24Questions: 0Answers: 0
edited February 2010 in General
I was looking at the "User selectable rows (multiple rows)" example and wanted to take advantage of the "function fnGetSelected( oTableLocal )" provided but was at a lost to figure out what "type" of object the aReturn variable. Further, I had no clue as to how to track down the methods attached to the object. Can someone point me in the right direction?

Replies

  • dneedlesdneedles Posts: 24Questions: 0Answers: 0
    Ok I added:
    [code] alert("FISH"+ aReturn );
    return false;[/code]
    And got the type: HTMLTableRowElement. Now how do I find out what the heck I can do with it? In particular I want to pass this information via a button to the server.
  • dneedlesdneedles Posts: 24Questions: 0Answers: 0
    Hmm that wasn't much help. A grep of both jquery and jquery.dataTables for HTMLTableRowElement came up blank. Blah.
  • dneedlesdneedles Posts: 24Questions: 0Answers: 0
    OK. Found the reference. http://krook.org/jsdom/HTMLTableRowElement.html
  • dneedlesdneedles Posts: 24Questions: 0Answers: 0
    Hmm didn't realized javascript had gotten so deep. Can anyone point me to a tutorial on how the object model and methods work? Also any references they use?
  • dneedlesdneedles Posts: 24Questions: 0Answers: 0
    Found some jquery methods here: http://api.jquery.com/category/manipulation/
  • dneedlesdneedles Posts: 24Questions: 0Answers: 0
    Ah found a way to dump an object along with its methods:
    [code]
    // DIAGNOSTIC FUNCTION
    function dumpObj(obj, name, indent, depth) {
    if (depth > MAX_DUMP_DEPTH) {
    return indent + name + ": " + depth + "\n";
    }
    if (typeof obj == "object") {
    var child = null;
    var output = indent + name + "\n";
    indent += "\t";
    for (var item in obj)
    {
    try {
    child = obj[item];
    } catch (e) {
    child = "";
    }
    if (typeof child == "object") {
    output += dumpObj(child, item, indent, depth + 1);
    } else {
    output += indent + item + ": " + child + "\n";
    }
    }
    return output;
    } else {
    return obj;
    }
    }
    [/code]
    That did the trick along with the DOM and jquery API references:
    http://krook.org/jsdom/HTMLTableRowElement.html
    http://api.jquery.com/category/manipulation/
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Haha - nice monologue ;-)

    console.dir() in Firebug / Webkit's Inspector is awesome for this kind of thing. And doesn't require functions to be included.

    Allan
This discussion has been closed.