Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separate event handler functions for an event attached to different inputs or one event handler function with lot of if statements/ switch statement? #1783

Open
unitedsol opened this issue Apr 12, 2018 · 1 comment
Labels

Comments

@unitedsol
Copy link

@unitedsol unitedsol commented Apr 12, 2018

separate event handler functions for an event attached to different inputs or one event handler function with lot of if statements/ switch statement?

// event handler 1
function validateEmail() {
	// validate email here
}

// event handler 2
function validatePassword() {
	//validate password here
}

// or

// generic event handler
function validateFields() {
	/*
	if(is email){
		validate email
	}

	if(is password) {
		validate password
	}
	*/
}
@ljharb
Copy link
Collaborator

@ljharb ljharb commented Apr 14, 2018

This really isn’t the kind of thing this guide currently addresses, but personally I’d tend towards separate ones - it’s easier to unit test, and when something goes wrong, you have way less code to debug.

@ljharb ljharb added the question label Apr 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.