Review.md Project Notes
Loose observations from working on Review.md.
published Mar 16, 2017 tags
#javascript
#notes
~/posts/reviewmd-stuff $ cat post.md
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,
thisno longer points where you’d expect.- The truth about
this:obj.fn()is sugar. The real shape of calling a method on an object isfn.call(this, arg1, arg2)—thisis something you control explicitly. With the sugar,thisauto-points to the calling object; without a calling object, it falls back towindow. - When a method is passed out,
thisshifts under you and it gets hard to track. If you can avoid relying onthisfrom a passed-out method, do.
- The truth about
- You often can’t just call a method directly, because JS defers
activation a lot —
- 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=valuein 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
leterrored;varworked. The reason is hoisting —vardeclarations are hoisted to the top of the scope,letdeclarations 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
clickevent.- A component’s
datamust be a function. It can be a function that returns an object.
- A component’s
- Splitting a file on
\nis a fine way to read it line by line. - Planning to move the popular-action buttons onto GitHub too so they can update live.