UNPKG

sku-pg

Version:

Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!

120 lines (102 loc) 3.34 kB
<!DOCTYPE html> <html> <!-- Copyright 2007 The Closure Library Authors. All Rights Reserved. Use of this source code is governed by an Apache 2.0 License. See the COPYING file for details. --> <head> <title>Debug</title> <script type="text/javascript" src="../base.js"></script> <script type="text/javascript"> goog.require('goog.debug'); goog.require('goog.debug.FancyWindow'); goog.require('goog.debug.Logger'); /** * Person - a sample person object. * @param {string} name The name * @param {number} age The age */ var Person = function(name, age) { this.name_ = name; this.age_ = age; this.address_ = null; this.kids_ = []; /** * Set the address. * @param {string} address The address to set */ this.setAddress = function(address) { this.address_ = address; } /** * Add a child. * @param {Object} child The child to add */ this.addChild = function(child) { this.kids_.push(child); } /** * Create a string representation of the object. * @return {string} The object as a string */ this.toString = function() { return 'Person name: ' + this.name_ + ' Age: ' + this.age_; } } /** * Demonstrate the debug options. */ var demoDebug = function() { // Create the debug window. var debugWindow = new goog.debug.FancyWindow('main'); debugWindow.setEnabled(true); debugWindow.init(); // Create a logger. var theLogger = goog.debug.Logger.getLogger('demo'); theLogger.info('Logging examples'); // Create a simple object. var someone = {'name': 'joe', 'age': 33, 'gender': 'm', 'kids': ['jen', 'sam', 'oliver'], 'address': '233 Great Road, Axtonhammer, MD'}; // Show the object, note that it will output '[object Object]'. theLogger.info(someone); // Use expose to walk through the object and show all data. theLogger.info('Person: '+ goog.debug.expose(someone)); // Now create a Person object to demonstrate expose w/functions. var pObj = new Person('fred', 2); // Add a child, and an address. pObj.addChild(someone); pObj.setAddress('1 broadway, ny, ny'); // The toString will be called. theLogger.info('toString: '+ pObj); // Does not show the functions by default. theLogger.info('expose (no functions): ' + goog.debug.expose(pObj)); // You can specify false if you really want to. theLogger.info('expose (no functions): ' + goog.debug.expose(pObj, false)); // Shows the functions as well. theLogger.info('expose (w/functions): ' + goog.debug.expose(pObj, true)); // Show deepExpose, which walks recursively through data. theLogger.info('deepExpose (no functions): '+ goog.debug.deepExpose(pObj)); // You can specify false if you really want to. theLogger.info('deepExpose (no functions): '+ goog.debug.deepExpose(pObj, false)); theLogger.info('deepExpose (w/functions): '+ goog.debug.deepExpose(pObj, true)); theLogger.shout('shout'); theLogger.severe('severe'); theLogger.warning('warning'); theLogger.info('info'); theLogger.fine('fine'); } </script> <body> Look in the log window for debugging examples. </body> <script> // Call the demo method. demoDebug(); </script> </html>