Created
April 3, 2016 17:29
-
-
Save anonymous/9ae99f9dc8575f0cdc32cb7e4a9a35eb to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/wosato
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// tiny template engine function | |
function tpl(str,obj){ | |
for(var key in obj) { | |
str=str.replace(new RegExp('{' + key + '}','g'), obj[key]); | |
} | |
return str; | |
} | |
// code example | |
console.clear(); | |
var params = { name: 'John', language: 'JavaScript', skills: 'coding' }; | |
var query = 'Hello {name}, do you want to learn {language} {skills}?'; | |
var res = tpl(query, params); | |
console.log(res); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// tiny template engine function | |
function tpl(str,obj){ | |
for(var key in obj) { | |
str=str.replace(new RegExp('{' + key + '}','g'), obj[key]); | |
} | |
return str; | |
} | |
// code example | |
console.clear(); | |
var params = { name: 'John', language: 'JavaScript', skills: 'coding' }; | |
var query = 'Hello {name}, do you want to learn {language} {skills}?'; | |
var res = tpl(query, params); | |
console.log(res);</script></body> | |
</html> |
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
// tiny template engine function | |
function tpl(str,obj){ | |
for(var key in obj) { | |
str=str.replace(new RegExp('{' + key + '}','g'), obj[key]); | |
} | |
return str; | |
} | |
// code example | |
console.clear(); | |
var params = { name: 'John', language: 'JavaScript', skills: 'coding' }; | |
var query = 'Hello {name}, do you want to learn {language} {skills}?'; | |
var res = tpl(query, params); | |
console.log(res); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment