News for hackers. Stuff that matters.
Re:A game whose source code fits in one tweet by shubhamjain on Monday June 29, 2015 @11:49PM (#9802830)
OP can save a few more characters by not using 'var' and using 'E' notation for representing 15000, i.e, 15E3, or better, 2E4.
Re:A game whose source code fits in one tweet by ivanca on Tuesday June 30, 2015 @02:48AM (#9803385)
He can save 14 more if instead of creating a function he copies the function content inside of 'onclick'. And he can save one by using +new Date instead of Date.now().
Re:A game whose source code fits in one tweet by sgibat on Tuesday June 30, 2015 @06:58AM (#9804260)
Better yet, set a variable to Date.now since it's called twice.
Re:A game whose source code fits in one tweet by ajanuary on Tuesday June 30, 2015 @09:26AM (#9804988)
It's called at different times so will return different values, which is important.
Re:A game whose source code fits in one tweet by ahoge on Tuesday June 30, 2015 @12:36PM (#9806502)
They meant something like "var n = Date.now".

However, there is no guarantee that this will work since it assumes that `this` isn't used by that function.

E.g. if you want to do something like that with console.log or document.querySelector, you have to use bind:

  var log = console.log.bind(console);
  var qs = document.querySelector.bind(document);
Re:A game whose source code fits in one tweet by roberto on Tuesday June 30, 2015 @01:21PM (#9806898)
a = Date.now; b = a(); c = a();
Re:A game whose source code fits in one tweet by microcolonel on Tuesday June 30, 2015 @01:32AM (#9803125)
Could also use `!0` for `true`.
Re:A game whose source code fits in one tweet by ninkendo on Tuesday June 30, 2015 @01:40AM (#9803140)
He could use the savings to close that <p> tag.
Re:A game whose source code fits in one tweet by latch on Tuesday June 30, 2015 @03:18AM (#9803503)
It isn't XHTML. Closing <p> tags are optional (which is true for many tags). You don't even need opening HTML, HEAD or BODY tags.
Re:A game whose source code fits in one tweet by nekkoru on Tuesday June 30, 2015 @05:05AM (#9803857)
That's only true in very specific cases: https://developer.mozilla.org/en/docs/Web/HTML/Element/p

The start tag is mandatory. The end tag may be omitted if the <p> element is immediately followed by an <address>, <article>, <aside>, <blockquote>, <div>, <dl>, <fieldset>, <footer>, <form>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <header>, <hr>, <menu>, <nav>, <ol>, <pre>, <section>, <table>, <ul> or another <p> element, or if there is no more content in the parent element and the parent element is not an <a> element.

Re:A game whose source code fits in one tweet by myfonj on Tuesday June 30, 2015 @07:37AM (#9804435)
And "there is no more content in the parent element" applies here.

Actually, what you call "very specific cases" are in fact, well, all reasonable cases. That list consists of all block level elements that can appear in `body`, so the statement could be reworded, that "<p> cannot contain any block-level element, so any inline element after <p> falls in, any block level element ends opened <p>".

Funny fact is that presence of optional end tags means nearly nothing for HTML parsers used in current browsers, they just ignore them. Some border cases regarding white space exists, or at least existed in the past, but in general, if you feed browser with document

    <!doctype html><html><head><title>a</title></head><body><table><tbody><tr><td><p>b</p></td></tr></tbody></table></body></html>`
or

    <!doctype html><title>a</title><table><tr><td><p>b</table>`
makes absolutely no difference. Both will result in exactly same DOM tree, both are "100% valid W3C HTML documents".