Quantcast
Channel: Extend Basic Types in TypeScript, Error: "_this is not defined..." - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by Thalles Noce for Extend Basic Types in TypeScript, Error: "_this is not defined..."

$
0
0

You need to extend the String interface like this:

interface String {    stringFormat(...args: string[]): string;}

and you need to implement like this

module Utilities {    String.prototype.stringFormat = function (): string {        var args = arguments;        return this.replace(/\{\{|\}\}|\{(\d+)\}/g, function (m, n) {            if (m == "{{") { return "{"; }            if (m == "}}") { return "}"; }            return args[n];        });    }}

implementation source:Equivalent of String.format in jQuery


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>