{"id":68,"date":"2013-04-29T22:38:58","date_gmt":"2013-04-29T14:38:58","guid":{"rendered":"http:\/\/blog.boviner.com\/?p=68"},"modified":"2013-04-29T23:15:47","modified_gmt":"2013-04-29T15:15:47","slug":"alexander-brevig-the-comment-toggle-trick","status":"publish","type":"post","link":"https:\/\/tongwing.woon.sg\/blog\/alexander-brevig-the-comment-toggle-trick\/","title":{"rendered":"Alexander Brevig : The \/\/* \/*\/ \/\/*\/ comment toggle trick"},"content":{"rendered":"<p>Just saw this on HN. <a href='https:\/\/coderwall.com\/p\/zbc2zw'>Alexander Brevig : The \/\/* \/*\/ \/\/*\/ comment toggle trick<\/a>.<\/p>\n<p>I&#8217;ve been using something very similar &#8211; the only difference between the last comment \/\/*\/ vs \/**\/<\/p>\n<p><code>\/\/*<br \/>\nsomeFunction();<br \/>\n\/*\/<br \/>\nsomeOtherFunction();<br \/>\n\/**\/<br \/>\n<\/code><\/p>\n<p>This technique is surprisingly &#8220;portable&#8221; &#8211; works in C++, Javascript, PHP, amongst others. And it works better than <code>if (0) { someFunction(); } else { someOtherFunction(); }<\/code> &#8216;cos syntax-highlighting works.<\/p>\n<p>Another trick that I&#8217;ve used by abusing comments is to produce output that are both valid Javascript as well as HTML &#8211; at least to most browsers:<\/p>\n<p><code>\/\/&lt;!--<br \/>\nalert(\"hello\");<br \/>\n\/\/--&gt;<br \/>\n\/\/&lt;html>&lt;body>some text&lt;\/body>&lt;\/html><\/code><\/p>\n<p>In Javascript context it&#8217;ll show a &#8220;hello&#8221; prompt, whereas in HTML context it&#8217;ll show &#8220;\/\/ \/\/some text&#8221;. This can be used when say you&#8217;re returning a Javascript API and someone is misinterpreting it as HTML. You can of course be creative about the &#8220;some text&#8221; part. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just saw this on HN. Alexander Brevig : The \/\/* \/*\/ \/\/*\/ comment toggle trick. I&#8217;ve been using something very similar &#8211; the only difference between the last comment \/\/*\/ vs \/**\/ \/\/* someFunction(); \/*\/ someOtherFunction(); \/**\/ This technique is surprisingly &#8220;portable&#8221; &#8211; works in C++, Javascript, PHP, amongst others. And it works better than [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/tongwing.woon.sg\/blog\/wp-json\/wp\/v2\/posts\/68"}],"collection":[{"href":"https:\/\/tongwing.woon.sg\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tongwing.woon.sg\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tongwing.woon.sg\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tongwing.woon.sg\/blog\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":11,"href":"https:\/\/tongwing.woon.sg\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"predecessor-version":[{"id":76,"href":"https:\/\/tongwing.woon.sg\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions\/76"}],"wp:attachment":[{"href":"https:\/\/tongwing.woon.sg\/blog\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tongwing.woon.sg\/blog\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tongwing.woon.sg\/blog\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}