This project is read-only.

Templates instead of generics

Topics: General, Language Specification
Jul 22, 2014 at 11:42 AM
IMO templates are more powerful then generics. The only drawback on templates is a larger footprint at runtime. Types are however irrelevant in JavaScript and removed during compilation. The larger footprint is therefore a nonissue in this case.

What is the reason not to support templates instead of generics? Will it increase – substantial – the complexity of the compiler?
class ParentClass {
   constructor() {
      this.childNode = new ChildClass<ParentClass>(this);
   private childNode: ChildClass<ParentClass>;
   public Test(): number{ return 1; }

class ChildClass<T> {
   constructor(T parentNode) {
      this.parentNode = parentNode;
   private parentNode:T;
   public Test():number { return this.parentNode.Test(); }
Jul 29, 2014 at 6:26 AM
If you mean by templates some kind of code generation then it is much better to add macros operating on syntax tree.