Access to class scope inside lambda in TypeScript is undefined?
<p>I have the following class in TypeScript that is used as a Pipe by Angular 2 to render markdown. It compiles without errors, but hits an exception at runtime on the marked line:</p>

<pre><code>var Remarkable = require('remarkable');

@Pipe({
    name: 'markdown'
})
export class MarkdownPipe implements PipeTransform {
    public remarkable;

    constructor(private sanitizer: DomSanitizationService) {
        this.remarkable = new Remarkable({
            typographer: true
        });

        this.remarkable.use(this.parseVideos);
    }

    transform(value: string) : SafeHtml {
        if (value != null) {
            return this.sanitizer.bypassSecurityTrustHtml(this.remarkable.render(value));
        }
        return null;
    }

    public parseVideos(md) : void {
        md.inline.ruler.push('video', (state) =&gt; {
            return this.parseMedia(state, '@', 'video'); // this is undefined
        });
    }

    public parseMedia(state, startingMarker, tokenName) : boolean {
        // do stuff
    }
}
</code></pre>

<p>When I this code attempts to execute, I get a runtime error telling me that:</p>

<p><img src="https://i.imgur.com/2M0fP9F.png" alt=""></p>

<p>Where <code>_this</code> refers to the same line I have commented above. Why is this? My IDE reports that I should have access to the <code>parseMedia</code> method inside of my lambda expression.</p>

<p><img src="https://i.imgur.com/jIPxcnP.png" alt=""></p>

<p>What's the best solution to this? </p>