-
Notifications
You must be signed in to change notification settings - Fork 0
/
If.js
34 lines (24 loc) · 1.05 KB
/
If.js
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
class If {
constructor(expression, scope) {
this.expression = expression || ""; /** */
this.code = null; /** */
this.value = null; /** */
this.scope = scope || null; /** */
this.nodeListTrue = []; /** */
this.nodeListFalse = []; /** */
}
run() {
this.value = this.code.eval(this.scope).entries[0];
if(this.value) { for(var t in this.nodeListTrue) { this.nodeListTrue[t].run(); } }
else { for(var f in this.nodeListFalse) { this.nodeListFalse[f].run(); } }
}
compileExpression() {
this.expression = Util.checkScope(this.expression, this.scope); /** Comprobamos si hay que actualizar la expresion y el scope. */
this.code = math.compile(this.expression); /** Compilamos la expresion con Math.js. */
}
destroy() {
Util.deepDestroy(this.nodeListTrue);
Util.deepDestroy(this.nodeListFalse);
Util.deepDestroy(this);
}
}