Differences with JS

ECMAScript 3 & 5

Objects

ECMAScript 3

var x = { // object "x" with 3 props: a, b, c
  a: 10, // primitive
  b: {z: 100}, // object "b" with prop z
  c: function () { // function (method)
    console.log('method x.c');
  } 
};

console.log(x.a); // 10
console.log(x.b); // [object Object]
console.log(x.b.z); // 100
x.c(); // 'method x.c'

ECMAScript 5

var x = { // object "x" with 3 props: a, b, c
  a: 10, // primitive
  b: {z: 100}, // object "b" with prop z
  c: function () { // function (method)
    console.log('method x.c');
  } 
};

console.log(x.a); // 10
console.log(x.b); // [object Object]
console.log(x.b.z); // 100
x.c(); // 'method x.c'

Teh

// No objects nor hashes. You can use nested (multidimenstional) arrays.

var x = [
  a: 10,
  b: [z: 100],
  c: function (){
    console.log("x['c']");
  }
]

console.log(x["a"]); // 10
console.log(x["b"]); // [Array]
console.log(x["b"]["z"]); // 100
x["c"]; // "x['c']" (?) Handle the case. Usually you'd want assign the function to a variable before jamming it into the array.

Modules

ECMAScript 3

// None.

ECMAScript 5

// calculator/lib/calc.js
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.square = square;
exports.MY_CONSTANT = void 0;

var notExported = "abc";

function square(x) {
  return x * x;
}

var MY_CONSTANT = 123;
exports.MY_CONSTANT = MY_CONSTANT;

// calculator/main.js
var _calc = require("lib/calc");

Teh

1
2
3
4
5
6
7
8
// calculator/lib/calc.teh
module "calc";

var notExported = 'abc'; //not a case
function square(x) {
    return x * x;
}
%MY_CONSTANT = 123; // constants should use come kind of sigil, so they wouldn't be constantly shouting, calm down, geez

Teh-exlusive features

Packages

ECMAScript 3

// None.

ECMAScript 5

// None.

Teh

1
2
3
4
// calculator/calc.teh
package "calc";
import "math" from "lib/calc"; // importing as usual
pass "math" from "lib/calc"; // passing math from lib/calc, without making it visible to code within the current module or package, useful for namespacing.

(Better) typecasting & optional types

Teh

/*
-   (int), (integer) - cast to integer
-   (bool), (boolean) - cast to boolean
-   (float), (double), (real) - cast to float
-   (string), (str) - cast to string
-   (array), (arr) - cast to array
-   (unset), (nil), (null) - cast to null/nil
*/

var a = "3.5";
console.log((float)a); // 3.5, not a string anymore

var boo_true = true;
console.log((string)boo_true); //"true", cool, a string

console.log((array) 5);// value 5 in the array with 0th index 
console.log((array) null);// Will be empty array

// you can use optional types when the expected result type is known
int b = 5; //int variable b
str c = "wow"; //string variable c

Dump() alias

Teh

1
2
3
4
5
6
7
// dump() is an alias for console.log which allows to quickly debug values

a = 2;
dump(a); //int a(2)

int b = 3;
dump(b); //int b(3)

Optional dot notation for arrays

Teh

var a = [
    b: 10,
    c: [
      c1: 1,
      c2: 2
    ]
]

console.log(a.c.c1) // 1
console.log(a.b) // 10
Edit

Pub: 01 Nov 2019 07:38 UTC

Views: 202