Skip to content

Javascript

Anton Istomin edited this page Feb 19, 2020 · 6 revisions

Javascript

Scientific string coercion performance comparison

I (very carefully) measured that '' + something is 5% faster than String(something). I still prefer latter for string coercion.

Node: require cyclic dependencies

require() returns {} when requiring a cyclically dependent module. I'd rather have a warning.

socket.io custom headers

let socket = require("socket.io-client")("http://www.example.com", { extraHeaders: { Cookie: "foo=bar; baz=qux" }})

Javascript remote debugging

There's a service for that: https://console.re/

Simulating a HTTP redirect in JS

(source: https://stackoverflow.com/a/506004)

window.location.replace("https://stackoverflow.com");

Node: require JSON

Yes, you may require JSON.

const data = require('./data.json');
  push(%rbp)
  %rbp = %rsp
  push(%r13)
  push(%rax)
  %rbp[-0x10] = $0x0, 
  %rbp[-0x10] = %r13, 
  %eax = 0
  %edi = 0
  callq 0x10f5109f0
  %r13 = %rax
  %rdi = %r13
  main()
  %rsp += $0x8
  popq   %r13
  popq   %rbp
  retq

Clone this wiki locally