Search code examples
javascriptractivejs

The logic behind Ractive.DEBUG minify assertion


I saw in Ractive docs this line of code:

Ractive.DEBUG = /unminified/.test(function() {/*unminified*/});

Can you explain the logic behind this ? The function should have the same value, despite whether it has inline comments or not.


Solution

  • Minification will remove the comment from the code so the function becomes function() {} when regex test calls .toString() on the function, thus yielding false.

    Without minification, the regex test will find the occurrence of unminified and therefore DEBUG will be true