Skip to content

Instantly share code, notes, and snippets.

View stevelounsbury's full-sized avatar

Steve Lounsbury stevelounsbury

  • ReturnBear
  • Ottawa, ON
View GitHub Profile
/**
* Allow for some super easy templating
* @param {Object} ctx The context when you pass in an object literal
* ------------------------------------------------------------------
* Works like this:
* var People = { name: 'bob', age: 123, decades: function() { return parseInt(this.age/10); } }
* var my_tpl = "Hi, my name is {{ name }} and I'm {{ age }} years old (that's {{ decades }} decades!)."
* my_tpl.template(People); // Outputs: "Hi, my name is bob and I'm 123 years old";
*/
String.prototype.template = function(data){