Skip to content

Instantly share code, notes, and snippets.

@michaellee8
Created June 2, 2017 11:43
Show Gist options
  • Save michaellee8/6a8b2cf284bbf3e70f34d5c63276c357 to your computer and use it in GitHub Desktop.
Save michaellee8/6a8b2cf284bbf3e70f34d5c63276c357 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/hinubiw
<!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">
String.prototype.formatUnicorn = String.prototype.formatUnicorn ||
function() {
"use strict";
var str = this.toString();
if (arguments.length) {
var t = typeof arguments[0];
var key;
var args = ("string" === t || "number" === t) ?
Array.prototype.slice.call(arguments) : arguments[0];
for (key in args) {
str = str.replace(new RegExp("\\{" + key + "\\}", "gi"), args[key]);
}
}
return str;
};
var testResponse = {
q: "abc{0}def{1}",
a: ["xx", "yy"]
};
</script>
<script id="jsbin-source-javascript" type="text/javascript">String.prototype.formatUnicorn = String.prototype.formatUnicorn ||
function() {
"use strict";
var str = this.toString();
if (arguments.length) {
var t = typeof arguments[0];
var key;
var args = ("string" === t || "number" === t) ?
Array.prototype.slice.call(arguments) : arguments[0];
for (key in args) {
str = str.replace(new RegExp("\\{" + key + "\\}", "gi"), args[key]);
}
}
return str;
};
var testResponse = {
q: "abc{0}def{1}",
a: ["xx", "yy"]
};
</script></body>
</html>
String.prototype.formatUnicorn = String.prototype.formatUnicorn ||
function() {
"use strict";
var str = this.toString();
if (arguments.length) {
var t = typeof arguments[0];
var key;
var args = ("string" === t || "number" === t) ?
Array.prototype.slice.call(arguments) : arguments[0];
for (key in args) {
str = str.replace(new RegExp("\\{" + key + "\\}", "gi"), args[key]);
}
}
return str;
};
var testResponse = {
q: "abc{0}def{1}",
a: ["xx", "yy"]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment