-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs.html
280 lines (246 loc) · 6.58 KB
/
js.html
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta charset="utf-8">
<title>Java</title>
<style>body{font-size: 12px}code,pre{margin:0;padding:0;}
body>pre{white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space: -o-pre-wrap;word-wrap:break-word;}f
</style>
</head>
<body>
<pre>
.table { display: table }
.tr { display: table-row }
.thead { display: table-header-group }
.tbody { display: table-row-group }
.tfoot { display: table-footer-group }
.col { display: table-column }
.colgroup { display: table-column-group }
.td, .th { display: table-cell }
.caption { display: table-caption }
alert(await new Promise((r)=> {
setTimeout(() => r("d"), 1000)
}));
new Promise((resolve, reject) => {
console.log('Initial');
resolve();
})
.then(() => {
throw new Error('Something failed');
console.log('Do this');
})
.catch(() => {
console.log('Do that');
})
.then(() => {
console.log('Do this, no matter what happened before');
});
const w = (ms) => new Promise((fn, reject) => setTimeout(fn, ms));
for (var i = 0; i < 3; i++) {
// Log `i` as soon as each promise resolves.
w(i * 100).then(() => console.log(i));
}
p1.then(
// Log the fulfillment value
function(val) {
log.insertAdjacentHTML('beforeend', val +
') Promise fulfilled (<small>Async code terminated</small>)<br/>');
}).catch(
// Log the rejection reason
(reason) => {
console.log('Handle rejected promise ('+reason+') here.');
});
async function asyncCall() {
console.log('calling');
var result = await resolveAfter2Seconds();
console.log(result);
// expected output: "resolved"
}
asyncCall();
// yield
function* foo(index) {
while (index < 2) {
yield index++;
}
}
const iterator = foo(0);
console.log(iterator.next().value);
console.log(iterator.next().value);
</pre>
</pre>
<p>
</p>
<table width="100%" border="1">
<tr>
<td>await</td>
<td>async</td>
<td>Promises</td>
<td>regular old javascript</td>
</tr>
<tr>
<td><pre>function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function asyncCall() {
console.log('calling');
var result = await resolveAfter2Seconds();
console.log(result);
// expected output: "resolved"
}
asyncCall();
</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<xmp>
Shell = new ActiveXObject("WScript.Shell");
DesktopPath = Shell.SpecialFolders("Desktop");
link = Shell.CreateShortcut(DesktopPath + "\\test.lnk");
// link.Arguments = "1 2 3";
link.Description = "test shortcut";
// link.HotKey = "CTRL+ALT+SHIFT+X";
// link.IconLocation = "app.exe,1";
link.TargetPath = "C:\\Program Files\\Mozilla Firefox\\firefox.exe";
// link.WindowStyle = 3;
// link.WorkingDirectory = "c:\\blah";
link.Save();
</xmp>
<pre>
$ = document.querySelectorAll.bind(document);
NodeList.prototype.__proto__ = Array.prototype;
NodeList.prototype.on = function (name, fn) {this.forEach(function (e, i) {e.addEventListener(name, fn);});}
NodeList.prototype.attr = function(){this.forEach(function (e, i) {e.addEventListener(name, fn);}
NodeList.prototype.append;
NodeList.prototype.prepend;
atom.io is the best text editor for JavaScript
<a href="https://mathematica.stackexchange.com/questions/152767/support-javascript-subset">JS Subset</a>
tag = (str)=>{return str.raw[0].replace(/\\\{/g,"{")}
tag`$\{a}
$\\{b}`
Semicolons are not optional
https://reactjs.org/docs/jsx-in-depth.html
function Foo() {}
Foo.prototype.toString = function() {
return 'hello'
}
(function() {
console.log('hi')
})
I can not find the question but I believe the biggest problem with trying to subset JavaScript inside Mathematica is the fact the nesting of addition and multiplication among others operations. Nothing nests properly
An example is the following.
Function[x,Return[x*23+4];] function(){return x*23+4}
The prototype chain is also interesting.
x.prototype.test = Function[] x.prototype.test=function(){};
The trickest part comes when trying to nest functions of functions and prototypes.
x.prototype.test = Function[x,
Return[23];
];
ClojureScript might be a solution.</pre>
<h1>\JavaScript, Expanded Symbolic JS, Symbolic JS</h1>
<p>Conversion of Types between JavaScript and the Wolfram Language.<br>\[Colon] \[CircleDot] Dot[]</p>
<table style="width:100%" border="1"><tbody>
<tr>
<td width="25%"><pre>node Hello.js</pre></td>
<td width="25%">Symbolic JavasScript</td>
<td width="25%">Expanded Symbolic JavaScript</td>
<td width="25%">[</td>
</tr>
<tr>
<td><pre>(function(x,str,y,z){
x = new y(z);
y.prototype.test = function(){alert(this)};
y = Object({});
y[test] = 23;
y = [];
y = Array();
y = {y:23};
x = function(){};
_t_ = $test;
_ = require("underscore.js");
z = null || undefined;
multilineString = "1
2";
return 2*Math.pow(2,3);
))(1,"test",2,3);</pre></td>
<td><pre>Module[{x=1,str,y=,z=3},
x = new[y][z];
y.prototype.test = Function[{},alert[this];];
y = Object[{}];
y\[Colon]str = 23;
y = {};
y = Array();
y = {y->23};
x = function(){};
$`t`$ = $test;
`$ = require["undescore.js"];
z = null || undefined;
multilineString = `1
2`;
return[2*(2^3)];
]</pre></td>
<td></td>
<td width="25%">
</td>
</tr>
<tr>
<td>o.method(args);</td>
<td>o.method[args];</td>
<td></td>
<td width="25%"></td>
</tr>
<tr>
<td>MyClass.StaticPropertyOrField = 1;<br>
value = MyClass.StaticPropertyOrField;</td>
<td></td>
<td></td>
<td width="25%"></td>
</tr>
<tr>
<td><pre>int i = 1;
double d = 2;
int[] anArray;
anArray = new int[10][20];</pre>
</td>
<td>
<pre></pre>
</td>
<td></td>
<td width="25%"></td>
</tr>
<tr>
<td>
<pre>public class MyClass {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
public void Method(){<br>
System.out.println("Method")}
public static void staticMethod(){
System.out.println("Static method");
}
public MyClass(){<br>System.out.println("Test");}
}</pre>
</td>
<td>
<pre></pre>
</td>
<td></td>
<td width="25%"><pre></pre></td>
</tr>
<tr>
<td></td>
<td>For, If, Else, </td>
<td></td>
<td width="25%"></td>
</tr>
</tbody>
</table>
</body>
</html>