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

Remove unnecessary parentheses from bind.md example #4363

Merged
merged 1 commit into from
Oct 12, 2024

Conversation

danielsbird
Copy link
Contributor

When I saw this example using x-data="dropdown()" and other examples using x-data="dropdown" I wondered what caused this example to require parentheses. It seems like adding parentheses is redundant since the example code works both with and without them.

@browner12
Copy link
Contributor

I think it's fine as is, and probably more accurate. dropdown() is a function you are executing to return an object.

@danielsbird
Copy link
Contributor Author

@browner12 I agree with your reasoning.

How do you think Alpine's docs can help beginners like me understand that there's no difference between x-data="dropdown()" and x-data="dropdown"? Should all examples use x-data="dropdown()" instead of x-data="dropdown"?

@browner12
Copy link
Contributor

is kind of less of an Alpine question, and more of a JS question. Alpine does do some magic that allows you to omit the parentheses, and you're kind of not technically writing Javascript in the attribute, but IMO I treat it as valid Javascript, which is why I always use the parentheses.

consistency would be nice, and I would personally lean towards using the parentheses, but that's something a maintainer will have to decide.

@calebporzio calebporzio merged commit cfe9499 into alpinejs:main Oct 12, 2024
1 check passed
@ekwoka
Copy link
Contributor

ekwoka commented Oct 14, 2024

To clarify on the difference, if the function is nested in an object, and accesses this, the this will be different between with and without the parentheses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants