Created
November 18, 2016 09:00
-
-
Save internoma/82202db0b403610d22ac94c1cf4148b5 to your computer and use it in GitHub Desktop.
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 mtemplate = function(template, data){ | |
function replaceFn(match, prop){ | |
return (prop in data)? data[prop] : ''; | |
} | |
return template.replace(/\{\{(\w+)\}\}/g, replaceFn); | |
}; | |
var output = mtemplate('{{foo}} / {{bar}}', {foo : 'prueba foo', bar: 'prueba bar'}); | |
window.console.info(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment