News for hackers. Stuff that matters.
Re:Multiline strings in JavaScript by mappum on Saturday July 12, 2014 @06:20AM (#8024178)
That's a really smart hack, I didn't realize comments were included in the output of Function#toString. You could do other cool things, e.g. an annotation for type checking:

  function checkType(f) {
    return function(a) {
      var type = f.toString().match(/\/\/(.*)\n/)[1].trim();
      if(type !== typeof(a)) throw new Error('Invalid type');
      return f(a);
    }
  }
  
  var halve = checkType(function(n) {
    // number
    return n / 2;
  });
  
  halve(4); // returns 2
  halve('string'); // emits error
Re:Multiline strings in JavaScript by tlrobinson on Saturday July 12, 2014 @07:13AM (#8024259)
I didn't realize comments were included in the output of Function#toString

Probably because sometimes they're not, depending on the JavaScript engine (though perhaps all of the major modern browsers do)

Re:Multiline strings in JavaScript by mofle on Saturday July 12, 2014 @07:29AM (#8024287)
The following browsers return comments:

- Latest Chrome

- Firefox >=17

- Safari >=4

- Opera >=9

- Internet Explorer >=6

From: https://github.com/sindresorhus/multiline#compatibility

Re:Multiline strings in JavaScript by coldtea on Saturday July 12, 2014 @10:01AM (#8024558)
Not just "Latest Chrome". Chrome has been doing it for at least 2 years. I know, because I'm using it with it.
Re:Multiline strings in JavaScript by manojlds on Saturday July 12, 2014 @10:28AM (#8024608)
I think Chrome is mentioned as "Latest Chrome" because:

1) There have been so many versions and not easy to know what came when.

2) Most people get updated to Chrome latest automatically without any fuss.

Re:Multiline strings in JavaScript by msujaws on Saturday July 12, 2014 @01:39PM (#8025193)
In fact, (2) is not as true as it used to be. This graph, http://cdn.arstechnica.net/wp-content/uploads/2014/07/chrome..., shows that about 6-7 percent of worldwide browsers are out-of-date Chrome installs, and the trend is for that to grow.

From http://arstechnica.com/information-technology/2014/07/window...

Re:Multiline strings in JavaScript by mofle on Saturday July 12, 2014 @11:01AM (#8024723)
That's correct. Chrome is practically versionless.
Re:Multiline strings in JavaScript by igl on Saturday July 12, 2014 @09:41AM (#8024518)
Closure Compiler.