JavaScript实现存储HTML字符串

吃完晚饭,在翻各位大牛的博客,偶然看到一篇原创《原创--Javascript你意想不到的功能!!!》眼前一亮,
这思路确实霸气测漏,可以不用理会字符串的单引号和双引号的转义,因为人家用的是注释,注释当然什么都可以写。
不过原文写的略显羞涩,我来修改个版本,就当是日记记下、

PS:我是搞PHP的,让我想起了<<<语法(heredoc和nowdoc),那么就为他命名heredoc吧。

Function.prototype.heredoc = function(){
    // 利用 function 的注释来存储字符串,而且无需转义。
    var _str = this.toString(),
        s_pos = _str.indexOf("/*")+2,
        e_pos = _str.lastIndexOf("*/");
    return (s_pos<0 || e_pos<0) ? "" : _str.substring(s_pos, e_pos);
}

function fn(){
/*<table>
    <tr>
        <td>用户名</td>
        <td>密码</td>
    </tr>
    <tr>
        <td style="widht:20px;">@name</td>
        <td>zf123456</td>
    </tr>
</table>*/
}

var str_table = fn.heredoc();
console.log(str_table);
原文地址:https://www.cnblogs.com/52cik/p/heredoc.html