88 points aragonite 2 days ago 27 comments

TheSilva 1 hour ago | parent

  Object.prototype.message='alert\x281337\x29';Array.prototype.toString=Error.prototype.toString;Error.prepareStackTrace = Function;const x = new Error;x.valueOf=x.stack;+x;
Well, that's a mouthful! So many years and JavaScript still can do the most amazing, weird, awesome, scary, obscure, and sexy things in the world of coding.

customguy 41 minutes ago | parent

Yesterday I was re-using some shaders I had written a long time ago, and here's what I used to do multiline strings before the glorious backtick arrived on the scene...

    (function () {/*
      my awesome shader code
    */}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1]
... I can't call it sexy, but I also can't deny I felt a mixture of fear and arousal when I saw that.

fg137 5 minutes ago | parent

The prototype thing is quite unique among mainstream languages. It is kind of simple in principle and works well for what it intends to do, but god it causes so much confusion and is frequently a source of CVEs. valueOf combined with implicit conversion is a nightmare for production code.

semiquaver 1 hour ago | parent

JavaScript is so cursed.

user____name 53 minutes ago | parent

If I were to write a book on programming in JS, it would be a black cover with the JS Holy Trinity equality diagram in red, to emphasize its Satanic nature.

aktenlage 1 hour ago | parent

What's the purpose of the +x at the end?

emaro 1 hour ago | parent

I think to implicitly trigger the valueOf function.

undecidabot 1 hour ago | parent

The unary plus implicitly converts an expression to a number, which calls `valueOf` for non-primitive values.

pards 1 hour ago | parent

Off topic: This website looks like a ransom note

eviks 2 minutes ago | parent

Maybe it is, just requires a different parser

hans_castorp 1 hour ago | parent

This reminds me of "Creators admit Unix, C hoax" (e.g. https://www.gnu.org/fun/jokes/unix-hoax.html)

> We stopped when we got a clean compile on the following syntax:

    for(;P("\n"),R--;P("|"))for(e=C;e--;P("_"+(*u++/8)%2))P("| "+(*u/4)%2);

nathell 43 minutes ago | parent

How Perl was created:

‘Larry, throw the cat at the keyboard!’

MEEEOW!

‘What did it type?’

‘&}Ak'>v=4%Qe}9;’

‘OK, so let’s make this a syntax for hello world.’

nathell 1 hour ago | parent

I love this. This is a fun hack, but the article also hearkens back to pre-LLM days when people were still interested in _code_.

stigok 33 minutes ago | parent

Programmers are still interested in code

cm2187 28 minutes ago | parent

Weekend hobby!

mystifyingpoi 12 minutes ago | parent

Now there is Monday again, no more coding, back to babysitting agents.

CrendKing 42 minutes ago | parent

Not gonna work on Firefox, since according to the doc, Error.prepareStackTrace is an optional API and only implemented by V8.

fg137 10 minutes ago | parent

> optional API and only implemented by V8

aka "Chrome implemented this and wanted everyone else to do so as well"