Created
August 14, 2018 22:40
-
-
Save pbuzdin/6082ef00dc0126dfc43c3a6bff18ff1a to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/giridihoti
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> | |
<p>hui</p> | |
<script> | |
var templite = function (str, mix) { | |
return str.replace(RGX, function (x, key, y) { | |
x = 0; | |
y = mix; | |
key = key.trim().split('.'); | |
while (y && x < key.length) { | |
y = y[key[x++]]; | |
} | |
return y != null ? y : ''; | |
}); | |
}; | |
var RGX = /{{(.*?)}}/g; | |
document.querySelector('p').innerText = templite('Hello {{name}}!', { name: 'world' }) | |
//document.write(templite('ты {{name}}!', { name: 'пидор' })) | |
document.write(templite(` | |
<b>Ты {{name}}!</b> | |
<h1>alert('hui')</h1> | |
`, { name: 'пидорjr' })) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment