The Objectsheet       A casual, object-oriented data analysis tool
Launch in Browser

Home

Overview

Why?

Download/Try

Live Tutorial

Function Reference

Notes and Links

email developer

 

 

Scratch Section Overview

Scratch sections are for free-form calculations and inspection of the Objectsheet data structures. Scratch sections have no template, just a single text area to enter expressions and functions and view their results. To calculate the Scratch section, hit control-enter or click out of the textarea. All of the lines are calculated, one at a time.

The following rules govern the calculation and display of Scratch sections:

  • Each line in a scratch section is treated as a single expression and calculated, top to bottom. The only exception to this is when a line ends in an open curly brace "{", all lines up to an including one that contains a single closing curly brace "}" are evaluated as one. This allows you to define functions or complex data structures within Scratch sections. e.g.,
    addUnits = function(x) {
      return x+" cm.";
    }
    var car = {
      color:"green",
      weight:1120,
      doors:2
    }
  • When you hit control-enter in a Scratch section or click outside, it calculates all expressions, line-by-line. After calculating, each line will show a separator character ":=" followed by the result of the expression.
  • If the result of an expression takes up more than one line, the answer is surrounded by /*...*/
  • If the first character of a line is ":", the expression is still calculated, but the ":= ..." answer part is not shown, i.e. is supressed.
  • Answers are shown "unfolded". If the result of an expression is an array or an object, all elements are shown. Elements that contain nested arrays or objects are further unfolded.
  • The only objects that are not unfolded are Document Object Model (DOM) objects, which have circular references and thus infinite depth when unfolded. For DOM objects, just the tagname is shown as the result. To see the insides of a DOM object, use ssplay(node) (this is short for "simple splay", which shows attributes one-layer deep only).
  • You can create a variable that's referenced to the section using a statement this.variablename = .... You can reference this variable anywhere in the Objectsheet application using sectionname.variablename. You can also create a global variable by just assigning to the variable, e.g., variablename = .... Using the Javascript keyword var (e.g., var variablename = ...) will create a local variable, not referenceable outside that particular section.
  • To place comments in a Scratch Section, use the single-line Javascript comment operators: //.... Multi-line comments (/*...*/) are removed during each calculation.
  • Note: if an expression in an Scratch section causes the section to lose the focus (e.g., alert()) and you type control-enter to calculate, the Scratch section will calculate twice (once for control-enter and once for losing the focus).

The Scratch section is also good development environment for small Javascript functions— you can write a both function and expressions that test it in a single Scratch section, and evaluate them all with a single keystroke (control-enter).

Scratch Sections can be used for writing large or complex functions, but do not provide many features of proper code editors (line numbering, syntax highlighting, automatic line indenting). To develop more complex functions, it may be easier to use an external editor, then use includeObject(filename) to load it into the Objectsheet environment. This requires switching back and forth between editor and Objectsheet to update a function then test it, but once in the Objectsheet, a single control-enter will re-read the Javascript file and do any test calculations.

© Rich Knopman, 2008 (rich -amet- cometresearch -doaht- com)