Lively Kernel Tutorial: (12) Modifying Objects and JavaScript Code on the Fly
Since the Lively Kernel is built with JavaScript,
a highly dynamic programming language that does not require
applications to be compiled ahead of time, virtually every object
in the system can be modified at runtime.
On this tutorial page we have included a number of textual scripts
that you can execute and modify on the fly.
You can execute the scripts using the "evaluate as JavaScript code"
feature that is available in the popup menu of TextMorphs.
Notes:
To open the popup menu for TextMorphs, press the Alt key
while clicking the border area of the TextMorph (area surrounding the text).
TextMorphs can be edited and evaluated also using the following keyboard shortcuts.
(NOTE: these shortcuts do not work on all browsers. In some browsers
you may have to use the "Alt Gr" key instead):
Alt-S ("Save-It"): Save (accept) the changes / evaluate the entire contents as JavaScript code
Alt-D ("Do-It"): Evaluate the selected text as JavaScript code
Alt-P ("Print-It"): Evaluate the selected text as JavaScript code and replace selection with the result
Alt-I ("Inspect-It"): Open inspector for the object
Alt-A: Select All
Alt-X: Cut
Alt-C: Copy
Alt-V: Paste
Alt-Z: Undo
Some additional comments on text editing:
Typing replaces selection.
Double-clicking selects a word; triple-clicking selects the entire text.
Double-clicking near a bracket, parenthesis or a JavaScript comment (/* ... */)
selects text inside the brackets/parentheses/comment.
Try it yourself! Try evaluating the scripts that have been provided
in the four TextMorphs below.
Try modifying the scripts yourself to generate different kinds of graphical objects.
Note that the objects generated by these scripts are full-fledged graphical objects that can
be edited using handles, menus and other features presented earlier in this tutorial.