KindScript – A kinder JavaScript experience
github.com
github.com
The website is currently not public so I'm not going to try anything yet but as a co-foudner at an CS Ed-tech startup I'm going to keep my ears perked. MS has put out some really nice JS products recently.
Note: The https url to kindscript.com is listed on the git repo.
Lazarus is a free, cross platform IDE for Pascal and an excellent place to start: http://www.lazarus-ide.org/
It's superficially similar but it has all kinds of archaic quirks and lacks basic affordances like return values or short-circuiting (i.e. in order to evaluate `a AND b` Pascal evaluates both).
You might as well argue that beginners should start with Assembly. If you want to be unnecessarily cruel at least teach them something useful like C/C++.
Anybody have more luck.
var m = {};
m["__alpha__"] = 10;
m["__bravo__"] = 20;
m["__proto__"] = 30;
for(var k in m) console.log(k);
Result (in current JS): __alpha__
__bravo__
EDIT: To be clear, I want a Javascript that is consistent. Imho, the fact that __proto__ is a property is a hack. Also, I suspect that a lot of software written in Javascript is susceptible to injection bugs/attacks by using the string "__proto__" as input in various places. {
const m = {}
m.__alpha__ = 10
m.__bravo__ = 20
m.__defineGetter__('__proto__', () => 30)
Reflect.ownKeys(m).forEach(key => console.log(key))
}
EDIT: I can't format ... function count_unique_strings(l)
{
var m = {};
l.forEach(function(s)
{
m[s] = true;
});
var count = 0;
for(var k in m) ++count;
return count;
}
To see why this function is incorrect, run it with the following input: console.log(count_unique_strings(["alpha", "bravo", "bravo", "charlie"]));
console.log(count_unique_strings(["alpha", "bravo", "bravo", "__proto__"]));The implementation is wrong: you're using Object when you want to use Map. Object is not suitable for this, and seems like you know it, and it's in language specs.
Problem solved.
Why should you need to know that much about the guts of the language just to create an associative array that works properly?
A better approach is to just use Map.
var m = new Map();
const m = new Map();
m.set("__alpha__", 10);
m.set("__bravo__", 20);
m.set("__proto__", 30);
for (let k of m.keys()) {
console.log(k);
}Objects can be used as cheap maps but they're more than that. That's why ES2015 brought us Map and Set.