0

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

hey thank you i also found figured it out by wrapping the return statement in a class that has a method attached to it class bar{ test: any; constructor(other: any){ test = other; } bar= () =>{ console.log('adding to dictionary ') }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.