summaryrefslogtreecommitdiffstats
path: root/khtml/ecma/jsk.html
blob: 917c083e877de202822c83122f97273850f333e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<html>
<!--
Javascript Konsole (c) 2001 Till Krech <till@snafu.de>
Dieser Code unterliegt den Bedingungen der Gnu Public License Version 2.
-->
<head>
<title>Javascript Konsole</title>
<style type="text/css">
code {
        color:#444488;
}
em {
        font-weight: bold;
}
</style>
<script language="JavaScript">

function do_eval() {
        var fo = document.forms.fo;
	fo.restyp.value = "";
	fo.field.value = "";
	var fo = document.fo;
	var expr = fo.zeile.value;
	var result = eval(expr);
	fo.restyp.value = typeof(result);
        var tuedel = "";
        if (typeof(result) == "string") {
                tuedel = '"';
        }
	fo.field.value = tuedel + result + tuedel;
}

function do_properties() {
        var fo = document.forms.fo;
	fo.restyp.value = "";
	fo.field.value = "";
	var fo = document.fo;
	var expr = fo.zeile.value;
	var result = eval(expr);
        var i;
	fo.restyp.value = typeof(result);
	var fieldvalue = "";
        if (typeof(result) != "undefined") {
           for (i in result) {
                var tuedel = "";
                var propval = result[i];
                if (typeof(propval) == "string") {
                        tuedel = '"';
                }
                fieldvalue +=
                        i
                        + " [" + typeof(propval) + "] = "
                        + tuedel + propval + tuedel + "\n";
           }
           fo.field.value = fieldvalue;
        }
}


</script>
</head>
<body bgcolor="#dddddd">
<h1>JavaScript Konsole</h1>
<form name="fo">
<table bgcolor="#cccccc" cellspacing="1" cellpadding="8">
 <tr bgcolor="#ffeeee"><th  height="40" align="right">Expression</th><td><input name="zeile" type="text" size="60"></td></tr>
 <tr bgcolor="#eeeeee"><th align="right">Result Type</th><td><input name="restyp" readonly type="text" size="60"></td></tr>
 <tr bgcolor="#eeeeee"><th align="right">Result(s)</th><td><textarea readonly name="field" rows="10" cols="60"></textarea></td></tr>
<tr bgcolor="#ffeeee"><td>&nbsp;</td><td>
 <input type="button" value="list properties" onclick="do_properties()">
 <input type="button" value="evaluate" onclick="do_eval()">
 <input type="reset" value="clear fields"
</td></tr>
</table>
</form>
<h2>Explanation</h2>
<h3>Operation</h3>
<blockquote>
When <em>evaluate</em> is pressed, the given expression is evaluated and the result is displayed in the result(s) field.
In case of <em>list properties</em> being pressed, the result of the expression is taken as an object
and the objects properties are displayed with their type and value in the the result(s) field.
</blockquote>
<h3>Expression</h3>
<blockquote>
Expression must be a valid javascript expression, e.g.<br><code>window</code>
<br>or<br><code>document.body.innerHTML</code><br>or<br>
<code>"Today: " + (new Date()).toString()</code><br>
or<br>
<code>"Cablecar".match(/ab.*c/)</code>
<br>It is also possible to assign a value,
e.g.<br><code>document.getElementsByTagName('H1').item(0).innerText="Hello World"</code><br>
You may execute these examples by pasting them into the expression field.
</blockquote>
<h3>Result Type</h3>
<blockquote>
The type of the result of the given expression.
</blockquote>
<h3>Result(s)</h3>
<blockquote>
The result of the expression is implicitly converted to a primitive type by the javascript interpreter,
if <em>evaluate</em> was pressed. When <em>list properties</em> was pressed, a <code>for (var i in obj)</code> loop
is executed to list the properties. These object properties are in turn evaluated and their types and values
are displayed.
</blockquote>
<p>
<a href="mailto:till@snafu.de?subject=JavaScript%20Konsole">Till Krech</a>
</p>
<p>
<br>
</p>

</body>
</html>