String.prototype.replace(str,func) 例中func的参数问题?
<div id="myDiv"></div> <script>String.prototype.supplant = function(o){return this.replace(/{([^{}]*)}/g,function (a,b){var r = o[b];return typeof r==='string'?r:a;});};var template ='<table border="{border}">' +'<tr><th>Last</th><td>{last}</td></tr>' +'<tr><th>First</th><td>{first}</td></tr>'+'</table>';var data = {first:"Carl",last:"Hollywood",border:"2"};myDiv.innerHTML = template.supplant(data); </script>function (a,b){var r = o[b];return typeof r==='string'?r:a;}