back to index

Review.md Project Notes

Loose observations from working on Review.md.

published Mar 16, 2017 tags #javascript #notes

~/posts/reviewmd-stuff $ cat post.md

/ LANG EN / 中文
/ THEME / /

Loose observations collected while working on Review.md.

  • Passing methods around
    • You often can’t just call a method directly, because JS defers activation a lot — setInterval, ajax callbacks, file-read completion, and so on.
    • Once a method is passed out and called from somewhere else, this no longer points where you’d expect.
      • The truth about this: obj.fn() is sugar. The real shape of calling a method on an object is fn.call(this, arg1, arg2)this is something you control explicitly. With the sugar, this auto-points to the calling object; without a calling object, it falls back to window.
      • When a method is passed out, this shifts under you and it gets hard to track. If you can avoid relying on this from a passed-out method, do.
  • GitHub RAW can host static files like a poor person’s CDN, with the bonus that anyone can contribute via PRs.
  • getURLVar: pulls a value out of ?key=value in the URL. Not dynamically updatable.
  • Another small helper uses regex to escape &, +, and ? in strings passed through to PHP — those characters otherwise get eaten as separators. Could be made more robust.
  • In Safari, declaring a Vue object with let errored; var worked. The reason is hoisting — var declarations are hoisted to the top of the scope, let declarations are not.
  • One-off, shared resources can live in a common class to cut download count; CDN-hosted libraries also save server bandwidth.
  • Vue components can talk to outside variables via a hidden button’s click event.
    • A component’s data must be a function. It can be a function that returns an object.
  • Splitting a file on \n is a fine way to read it line by line.
  • Planning to move the popular-action buttons onto GitHub too so they can update live.
back to index