javascript - Implementing function overloading -


since javascript not support function overloading typescript not support it. valid interface declaration:

// function overloading in interface  interface ifoo{     test(x:string);     test(x:number); }  var x:ifoo; x.test(1); x.test("asdf"); 

but how can implement interface. typescript not allow code:

// function overloading in interface  interface ifoo{     test(x:string);     test(x:number); }  class foo implements ifoo{     test(x:string){      }     test(x:number){      } } 

try it

function overloading in typescript done this:

class foo implements ifoo {     test(x: string);     test(x: number);     test(x: any) {         if (typeof x === "string") {             //string code         } else {             //number code         }     } } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -