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

Allow users of Vue to start their own private variables with `_` as is the convention in numerous other languages #9277

Closed
subdigit opened this Issue Jan 3, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@subdigit
Copy link

subdigit commented Jan 3, 2019

What problem does this feature solve?

Internal Vue variables that previously used _ can simply move to using __ or something else to avoid conflicts. Users from languages like Java have a tendency to start private variables with _ and because of the conflict that occurs with Vue's usage of _ starting variables, it can be a little mysterious as to why something is not working right.

What does the proposed API look like?

Switch Vue's internal variables to start with something other than _. End developers will not see a difference and will benefit from working code when they use semantics imported from other languages that typically use _ as a starting character to indicate private variables.

@Justineo

This comment has been minimized.

Copy link
Member

Justineo commented Jan 3, 2019

Precompiled render functions depends on render helpers start with _. ATM we cannot afford breaking existing code compiled by earlier versions of vue-template-compiler.

But you can still make this request once we start calling for RFC proposals for v3.0 some while later. Thanks.

@Justineo Justineo closed this Jan 3, 2019

@sirlancelot

This comment has been minimized.

Copy link
Contributor

sirlancelot commented Jan 3, 2019

You are free to start variables with _ or $. However, in order to access that variable, you need to go in to the $data object:

export default {
  data: () => ({
    _internal: "hello world"
  }),
  methods: {
    speak() {
        alert(this.$data._internal)
    }
  }
}

In templates:

<template>
  <div>
    {{ $data._internal }}
  </div>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment