Created
September 26, 2013 08:26
-
-
Save supasympa/6711373 to your computer and use it in GitHub Desktop.
Replace a string with model object properties
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
var M = function(){ | |
} | |
M.prototype = { | |
format : function(){ | |
var s = "/data/mu/programs/{{programCode}}/campaign-mus/{{muid}}/validate"; | |
var r = /{{[a-zA-Z_-]*}}/gi.exec(s); | |
var key = ''; | |
while(r!==null){ | |
key = r[0].replace('{{','').replace('}}',''); | |
s = s.replace(r[0], this[key]); | |
r = /{{[a-zA-Z_-]*}}/gi.exec(s); | |
} | |
return s; | |
} | |
} | |
var m = new M(); | |
m.programCode = 'YETI'; | |
m.muid = 9999; | |
m.format(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment