Remember String.Supplant()?

Its the nifty little tool that lets you do this.

  1. "The date today is {todayDate}, thank you {name}".supplant(
  2.   { "todayDate" : new Date().toString(), "name" : "Clark Kent" }
  3. );

Normally you would need to include the prototype supplied by Douglas Crockford on the page for you to be able to use this, but if you are using the Mootools library then its already built in.

String Method: Substitute

  1. var myString = "{subject} is {property_1} and {property_2}.";
  2. var myObject = {subject: 'Jack Bauer', property_1: 'our lord', property_2: 'savior'};
  3. myString.substitute(myObject); //Jack Bauer is our lord and savior
No comments

Leave a Reply