Created
May 16, 2014 05:12
-
-
Save laispace/f970f5ff8e22488c73cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void function() { | |
function format(template, json) { | |
return template.replace(/#\{(.*?)\}/g, function(all, key) { | |
return json && (key in json) ? json[key] : ""; | |
}); | |
} | |
document.getElementById('panel').innerHTML = format( | |
String(function(){/*! | |
<ul> | |
<li>#{title} -- #{date}</li> | |
<li>把模板放在注释里</li> | |
<li>这样就可以写多行了。。。</li> | |
</ul> | |
*/}).replace(/^[^\{]*\{\s*\/\*!?|\*\/[;|\s]*\}$/g, ''), | |
{ | |
title: "代码里的模板", | |
date: "2014-05-16" | |
} | |
); | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment