0

I want to pass in arguments into an onClick function, but it keeps firing on return. I believe I need to bind the click handler, but I am not exactly sure how to do that.

function (phone_calls, right_side, before_children) {

   
   function test (blah){
		console.log(blah)
    }




  return boxy(
    "Phone Calls",

    _.map(phone_calls, function(a) {



 	 return d("div.splitter-wrap", {onClick: test("testarg")}, [
 	   d("table.splitter", { className: name}, d("tr", 
 			[d('td',a.date),d('td',a.number)]
 	   	))
 	 ]);
}),

3
  • What is this my friend ? 🐚 spiral function😂 ! Commented Mar 21, 2017 at 18:36
  • Yeah... Trying to bind the onclick to the test function so ti wont fire on return Commented Mar 21, 2017 at 18:40
  • Try to call the callback function this way this.test.bind(this, 'testarg'). Commented Mar 21, 2017 at 18:42

1 Answer 1

1

you can use an arrow function, like:

{ onClick: ()=> { test("testarg") } }

otherwise you can use bind such as:

{ onClick: test.bind(this, "testarg") } 

but that is more verbose and has the (potentially) unwanted side-effect of setting this.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.