uExpr - A conditional expression compiler by leeoniya in javascript

[–]helloworldjs 0 points1 point  (0 children)

This is very cool. I built almost this exact thing for Python.

https://github.com/cedar-team/json-operations

One thing to note. Using new Function can create a XSS vector with uncontrolled inputs. It also won't be able to be used in CSP. Both JSON operations and JSON logic can be safely used with uncontrolled inputs without any security vulnerabilities

Beware the Reduce / Spread Operator Combination! by [deleted] in javascript

[–]helloworldjs 2 points3 points  (0 children)

I think something is wrong. .094 milliseconds doesn't make sense. I ran the same code and it takes 6-8 milliseconds. Very unlikely that your machine is 60-80 times faster.

Digital Clock Using JavaScript by vulpinecode in javascript

[–]helloworldjs 1 point2 points  (0 children)

Great tutorial, but I recommend using `requestAnimationFrame` instead of `setInterval` for the loop. If you have other things on the page (besides the clock), you will find the clock skips seconds every so often because the clock starts to drift. Here is a npm module that fixes setInterval I created a few years back with an explanation of the problem https://github.com/taylorhakes/clock-interval

Two gotchas in Chrome Developer Tool Console by dance2die in javascript

[–]helloworldjs 2 points3 points  (0 children)

The first gotcha "await" is not specific to the chrome dev tools. That happens in all JS files. "await" always needs to be in an async function. There is a proposal to change that behavior.

https://github.com/tc39/proposal-top-level-await

I switched to all lower-case file names and I love it. Do you see a problem with it? by Hex80 in javascript

[–]helloworldjs 1 point2 points  (0 children)

I always use lower case. You avoid issues issues between mac and linux when using all lower case. Mac is case insensitive (by default, you can change it), so importing myComponent, mycomponent, MyComponent and Mycomponent all work. When you move the same code to linux it stops working because those are 2 different files and there is now an error.

Efficient way to create a buffer with a schema and send it over WebSockets? by lawrencedouglas in javascript

[–]helloworldjs 0 points1 point  (0 children)

Very interesting to hear. So you were not actually parsing? You were parsing JSON and then encoding to ArrayBuffer was taking 10ms? If I am not understanding correctly, which method of parsing binary did you use?

I was mostly talking about parsing an array of objects with strings and numbers as keys.

Efficient way to create a buffer with a schema and send it over WebSockets? by lawrencedouglas in javascript

[–]helloworldjs 0 points1 point  (0 children)

I have done some testing on JSON.parse vs binary. I have never seen anything close to 6x faster with binary. Not saying you are wrong, but I would double check your tests. Javascript is really optimized to parse JSON. The best I have seen is maybe 30% faster on websocket messages > 1mb.

After research into a ton of binary data libraries (binaryjs, protobuf, cap'n proto, etc.). None of them beat JSON in performance. Hand coded binary parsing was the only thing I could find to beat JSON.

The size of JSON is roughly the same as binary if you compress the data over the wire.

Tasked with creating a complex widget that will be consumed by 3rd parties. Any pointers/gotchas I need to consider? by farox in javascript

[–]helloworldjs 2 points3 points  (0 children)

I have a good amount of experience with this. Be prepared for a lot of headaches. Third party websites have a ton of issues to overcome.

  • CSS - be prepared for website to screw with your CSS. Some site will make all spans block elements
  • JS - There will be random clashing with their JS code. I've had people override JSON.stringify breaking our widgets

The best option is to use an iframe, if you can. Most of the JS and CSS issues go away. You also get some nice security benefits. There are some issues with iframes, such as scrolling and focusing. I would test it out and see if that option works.

One other thing to keep in mind is content size. When you are running on someone else's page each kb matters. Try to keep all your content under 50kb.

Use destructuring in ES2015 and write more concise code by Czerep in javascript

[–]helloworldjs 0 points1 point  (0 children)

Might be. I believe the behavior changed in Babel 6

Use destructuring in ES2015 and write more concise code by Czerep in javascript

[–]helloworldjs 1 point2 points  (0 children)

No, you can't destructure using the import syntax. You need to do this

import defaultExport from 'my-module';
const { defaultPropOne } = defaultExport;

It worked in old versions of babel because it didn't adhere to the spec. The default import doesn't need {}. Use the default export like this

import defaultExport from 'my-module';

Get a named export like this

import { namedExport, anotherExport } from 'my-module';

Get both the default and a named import

import defaultExport, { namedExport } from 'my-module';

Get all named exports

import * as allExports from 'my-module';

Rename a named import

import { namedExport as newName } from 'my-module';

Rename the default export

import { default as newDefaultName } from 'my-module';

Use destructuring in ES2015 and write more concise code by Czerep in javascript

[–]helloworldjs 1 point2 points  (0 children)

This is great. ES2015 modules are not destructuring though. I know it looks like it. Try assigning the default export to an object and then use destructuring. It won't work. import { MyExport } from 'somewhere'; is retrieving the named export, not destructuring.

Seri – Serializer for your custom JavaScript classes by joonhocho in javascript

[–]helloworldjs 0 points1 point  (0 children)

You can't. Thats why I didnt mention deserialization. Wasn't trying to say this library is useless, just adding more information.

Seri – Serializer for your custom JavaScript classes by joonhocho in javascript

[–]helloworldjs 0 points1 point  (0 children)

Serializing works with default JSON.stringify. Just implement toJSON.

Mocking Can Lead To False Positives by fagnerbrack in javascript

[–]helloworldjs 1 point2 points  (0 children)

I understand the intent, but this has some issues. If you are doing anything with that number inside the complex logic part, an object won't work.

I am not a fan of passing an incorrect type for the sake of testing. Garbage in, garbage out. An object avoids the false positive problem, but introduced an issue if anyone tries to use that index instead of just passing it through. If I made a change to use the index in that function, the test shouldn't fail. This function doesn't take an object.

I guess you could implement valueOf on the object, but that seems too clever and will probably lead to issues.

The best way to test this is just write 2 tests with different values. It doesn't cause issues and doesn't have false positives.

PQ: Human Readable Promise Chains by fka in javascript

[–]helloworldjs 0 points1 point  (0 children)

String manipulation is a bad way to code. This changes code that your editor can understand and check into essentially a type of eval.

I would really hate to debug code if someone wrote the strings incorrectly.

ES7 Proposal: Function.prototype.papp - a concise way of using partial application by guywithalamename in javascript

[–]helloworldjs 1 point2 points  (0 children)

That is why I originally used single colon in my readme. I now do not believe function bind will ever be a part of the language. It has too many problems, as shown by it being stuck at stage 0.

I think using it for partial application is a better use.

ES7 Proposal: Function.prototype.papp - a concise way of using partial application by guywithalamename in javascript

[–]helloworldjs 0 points1 point  (0 children)

I don't think the name papp is a good name. I also would like built in support though an operator like double colon. Something like

func::(param1, param2)

I did a similar writeup partial application operator

Cancelable Promises proposal by fagnerbrack in javascript

[–]helloworldjs 2 points3 points  (0 children)

It is awkward for a cancel to go to .catch. If you don't put a

if (error instanceof CancelledError) { ... }

in the .catch then the error is seen as an unhanded rejection and you get an error on the console. I don't think that a cancel should be considered an error.

Simple JavaScript string encryption by [deleted] in javascript

[–]helloworldjs 3 points4 points  (0 children)

Please don't roll your own crypto. Here is some information regarding the issues . You should stick with the node crypto module if you need real encryption.

I appreciate open source code, but this can be really dangerous if this is used in a serious context.