keil
keil

Reputation: 39

extending a method in typescript

Hi all i currently have a method. and i would like to add an option to create a custom method once its been filled out when its called.

currently all my methods get call like

let test = foo(var)

I would like to have the option to add this on top of the current method

    let test = foo(var).bar('i want this added to current method')

I have no idea how to do this or even what this would be called.

Thank you

Upvotes: 0

Views: 33

Answers (1)

Vaibhav Bhuva
Vaibhav Bhuva

Reputation: 455

You can create a closure function to keep the value of an even after the inner function is returned

 
 function foo(param1){

  var bar =  function (param2) {
   return param1 + param2;
  }
  return { bar };

}

var test = foo("Hello").bar("World!");  

console.log(test);

Upvotes: 1

Related Questions