Javascript 实现HTML字符串的储存

     在js中使用HTML字符串时,可以不用理会字符串的单引号和双引号的转义,因为使用的注释,注释当然什么都可以写。

PS:这个有点类似于 php中的 <<<语法(heredoc和nowdoc),那么就为他命名heredoc吧。

Function.prototype.hereDoc = function(){
    var _str = this.toString(),
        _posS = _str.indexOf('/*') + 2 ;
        _posE = _str.lastIndexOf('*/') ;
        
    return (_posS < 0 || _posE < 0) ? '' : _str.substring(_posS, _posE) ;
}

function docWord(){
/*<table>
    <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
        <td>4</td>
    </tr>
    <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
        <td>4</td>
    </tr>
</table>*/
}

var table = docWord.hereDoc();
console.log(table);
原文地址:https://www.cnblogs.com/king516/p/3795895.html