这个确切的函数不适用于Node Js,即使它在常规浏览器上运行正常。如何使它在NodeJS上运行?
var MyHereDoc = function() {
var bodyEmail = function(){
var test = 1;
/*HEREDOC
<div>
Hola1
<p>
hola2
</p>
</div>
HEREDOC*/
};
var here = "HEREDOC";
var reobj = new RegExp("/\\*"+here+"\\n[\\s\\S]*?\\n"+here+"\\*/", "m");
str = reobj.exec(bodyEmail).toString();
str = str.replace(new RegExp("/\\*"+here+"\\n",'m'),'').toString();
toPrint = str.replace(new RegExp("\\n"+here+"\\*/",'m'),'').toString();
document.getElementById("demo").innerHTML = toPrint;
}
MyHereDoc();
如果您尝试在NodeJS上运行相同的代码,则会收到此错误:
Cannot call method 'toString' of null
但为什么?任何想法如何让它工作,或我做错了什么? 感谢