Login   Register  
Icontem

File: test.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Rubens Takiguti Ribeiro  >  var_dump  >  test.js  >  Download  
File: test.js
Role: Example script
Content type: text/plain
Description: Test source
Class: var_dump
Show variable values like PHP var_dump function
Author: By
Last change:
Date: 2011-04-07 05:57
Size: 1,346 bytes
 

Contents

Class file image Download
window.onload = function() {

    // Creating an object with scalar attributes
    var obj = new Object();
    obj.u = undefined;
    obj.n = null;
    obj.num = 3.5;
    obj.inf_p = Number.POSITIVE_INFINITY;
    obj.inf_n = Number.NEGATIVE_INFINITY;
    obj.str = 'Hello world';
    obj.bool1 = true;
    obj.bool2 = false;

    // Creating object attributes
    obj.obj_date = new Date();
    obj.obj_num = new Number(2.5);
    obj.obj_str2 = new String('Hello world');
    obj.obj_bool1 = new Boolean(true);
    obj.obj_bool2 = new Boolean(false);

    // Creating an array attribute    
    obj.arr = new Array();
    obj.arr.push('a');
    obj.arr.push(5);

    // Creating a method
    obj.foo = function() { window.alert('hi'); };
    obj.foo.prototype.pi = 3.14;
    obj.foo.prototype.msg = 'hello';
    obj.foo.prototype.func = function() { var x = 1; };

    // Calling JavaScript var_dump with the created object
    var result = var_dump(obj);

    // Calling JavaScript var_dump with the same object, but only 1 level of recursion
    var_dump.max_recursion = 2;
    var result2 = var_dump(obj);
    var_dump.max_recursion = 0;

    // Showing result
    document.getElementById("result_area").appendChild(document.createTextNode(result));
    document.getElementById("result_area2").appendChild(document.createTextNode(result2));
}