Javascript String apply(o)

Description

Javascript String apply(o)


'use strict';/*from   w ww  .j  ava2  s .co m*/

String.prototype.apply = function (o) {
    return this.replace(/{([^{}]*)}/g,
        function (a, b) {
            var r = o[b];
            return typeof r === 'string' || typeof r === 'number' ? r : a;
        }
    );
};



PreviousNext

Related