Created
June 2, 2017 11:43
-
-
Save michaellee8/6a8b2cf284bbf3e70f34d5c63276c357 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/hinubiw
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"> | |
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> |
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
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