oop - Extending String native type in Typescript -


i extend string type in typescript. here's code :

export class str extends string{     constructor(str: string) {         super(str);     } } 

the problem is, after call of string constructor using super(str), value of new type stills empty.

i have same problem type extending native array type.

thanks help.

your code transpiled to:

var __extends = (this && this.__extends) || function (d, b) {     (var p in b) if (b.hasownproperty(p)) d[p] = b[p];     function __() { this.constructor = d; }     d.prototype = b === null ? object.create(b) : (__.prototype = b.prototype, new __()); }; var str = (function (_super) {     __extends(str, _super);     function str(str) {         _super.call(this, str);     }     return str; })(string); 

and problem no longer deal original native type has special properties (like + operator on 2 strings). extended type - if have succeded - severely limited , confusing others.

details , gotchas can found axel rauschmayer's article: http://www.2ality.com/2013/03/subclassing-builtins-es6.html


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -