简体   繁体   中英

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM