我是搞PHP的,讓我想起了<<<語(yǔ)法(heredoc和nowdoc),那么就為他命名heredoc吧。
復(fù)制代碼 代碼如下:
Function.prototype.heredoc = function(){
// 利用 function 的注釋來(lái)存儲(chǔ)字符串,而且無(wú)需轉(zhuǎn)義。
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>@name</td>
<td>zf123456</td>
</tr>
</table>*/
}
var str_table = fn.heredoc();
console.log(str_table);
新聞熱點(diǎn)
疑難解答
圖片精選