by weberc2 · 9y ago · 0 comments
1. Lists and objects/dicts only; objects have no prototypes at all; objects have no first-class methods, but they can have functions as member variables, and those functions can close over other data in the object
2. All function and variable declaration is anonymous (as a consequence of 1); if you want to define a schema for an object, build a function that takes certain arguments and returns an object with the corresponding structure.
3. Coroutines/fibers/etc for async things; no promise/callback hell
4. Type annotations a la Python (not sure how this fits with 2 just yet)
EDIT: I did a bad job of emphasizing this, but syntax is important to me--I want something that looks like:
var foo = {
x: [1, 2, 3],
y: (a, b, c) => {
var sum = a + b + c;
sum * sum
},
}
Whether or not you agree that syntax should be a relevant criteria is a different matter. :) -- LuaJIT
local oldG = _G
local newG = setmetatable({}, {
__index = oldG,
})
setmetatable(oldG, {
__index = function(t, k)
return rawget(newG, k)
end,
__newindex = function()
error('attempt to assign global variable')
end,
})
_G = newG
If you want to assign a global variable, `x = 5` will error but `_G.x = 5` won't.If you want implicit returns and really want to disable "fancy features", babel plugins are fairly easy to create – blacklisting certain constructs wouldn't be very difficult, and implicit returns aren't so hard (you can copy my implementation[0] from a JS superset I built called LightScript[1]).
EDIT: bonus of building on babel is that you can get static types for free à la Flow (though typechecking implicit returns may be a pain).
[0] - https://github.com/lightscript/babel-plugin-lightscript/blob...
[1] - http://lightscript.org
foo = {
x: {1, 2, 3},
y: (a, b, c) ->
sum = a + b + c
sum * sum
}