Teh vs 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-exclusive 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.

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

Arrays

Arrays items' indexes in teh are strictly int, you can't refer to them as strings, however you can do that for items with keys.

Teh

var x = [
  1,
  2,
  3: ["three": 33,3]
];

console.log(x['3']);
// invalid
console.log(x[3]);
//array

All nested arrays are folded into [Array...] blocks when being output via console/print.

Constants

Teh

// None.

Local variables

Teh

var one = 1;

function one(){
  # lua approach
  local two = 2;
  console.log(one+","+two);
}
one();

#> 1,2
Edit
Pub: 11 Sep 2020 10:43 UTC
Edit: 11 Sep 2020 12:18 UTC
Views: 207