Show HN: I built an extension of JavaScript in a day
github.com
github.com
2. On the async functions – what happens if you put an async function inside a conditional? This is effectively solved by ES6's yield + co or an equivalent.
3. A nitpick, but, is there a way to create static functions on classes? E.g. Car.x instead of Car.prototype.x?
2. I'm not sure if I understand your correctly, but it should work if you wrap it in (). I actually have that very same example in 'broken.js' [0]
3. Sure. As you can write normal JavaScript, just use:
Car.x = (arg){
//etc
}
The ':' operator is supposed to be a shortcut for X.prototype.Y[0]: https://github.com/binlain/designtojs/blob/master/test/broke...
loadAndPrintFile: (contents) {
if (!contents) {
fs.readFile() -> (error!, contents)
}
console.log(contents);
}
i.e., expected behavior would be as if readFile was not an async function.I'm asking because I built something similar (though it only worked with promises, not general async functions), and I'm curious to compare approaches :-) - mine is a sweet.js macro: http://pastie.org/9410315 (uses https://github.com/petkaantonov/bluebird and https://github.com/BranchMetrics/promise-accum). The basic syntax would be:
task {
item1 <- LoadItem(1);
item2 <- LoadItem(item1.foreign_key);
ret <- DoSomethingWithItems(item1, item2);
}(again, beautified because DesignToJS crams everything in one line to preserve the line numbers of your actual code):
function loadAndPrintFile(contents) {
if (!contents) {
fs.readFile(function(error, contents){
if(error !== null && error !== undefined){
return error;
}
});
}
console.log(contents);
}
If you omit the function body, it will only expand to the end of the current logical 'context' (or whatever it's called)I'd suggest writing it like this in DesignToJS:
loadAndPrintFile: (contents! console.log) {
fs.readFile() -> (error!, contents! console.log)
}
Result looks like this: function loadAndPrintFile(contents) {
if(contents !== null && contents !== undefined){
return console.log(contents);
}
fs.readFile(function(error, contents){
if(error !== null && error !== undefined){
return error;
}
if(contents !== null && contents !== undefined){
return console.log(contents);
}
});
}
Edit: I just submitted a patch that avoids unnecessary binding of 'this' if 'this' is not actually used.Nevertheless, good luck with the project and everything.
Hello to undefined, nyc
You didn't tell me your age
When I'd assume you wanted Hello to nyc, Tim
You didn't tell me your ageIf you give a third, the second will be your age and the third your city.
Example:
sayHello('Andreas', 'Berlin')
sayHello('Andreas', 21, 'Berlin')Here is one such edge case:
(function () {
var undefined = true;
return (function foo(x) {
return x === undefined;
}());
}()); // false
Language pedantry aside, browsers these days will freeze `window.undefined` so you'd have to shoot yourself in your own scope ;)There's a test case in 'test/namedThings.(d)js'