Skip to content

Instantly share code, notes, and snippets.

@UlyssesWu
Forked from rednaxelafx/test.tjs
Created September 10, 2018 09:43
Show Gist options
  • Save UlyssesWu/ca3a314e660446d15153cfa4aa0fe24d to your computer and use it in GitHub Desktop.
Save UlyssesWu/ca3a314e660446d15153cfa4aa0fe24d to your computer and use it in GitHub Desktop.
TJS2 examples. Just a reminder. docs: http://devdoc.kikyou.info/tvp/docs/tjs2doc/contents/
class Foo {
var val;
property p {
getter {
return val;
}
setter(v) {
this.val = v;
}
}
function finalize() {
System.inform("finalize(): " + this);
}
}
var foo = new Foo();
foo.p = 123;
System.inform(foo);
System.inform(typeof foo);
System.inform(foo.p);
// var foo.bar = 'quux'; // can't do this
foo.bar = 'quux'; // can dynamically add members
System.inform(foo.bar);
(function () {
System.inform(this.bar);
} incontextof foo)();
delete foo.bar; // can dynamically remove members
// (function () {
// System.inform(this.bar);
// } incontextof foo)(); // member not found, exception
invalidate foo; // deterministically destroy object (like C++'s delete operator)
System.inform(isvalid foo); //=> 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment