admin管理员组文章数量:1290960
Every tutorial and code snippet I'm looking at while learning the framework all use var
for their declarations, including the official docs.
Preface, I'm just starting to learn Vue, so I know very little about it, but haven't found an answer yet.
Same with other like assuming property name:
new Vue({
data: data
})
vs.
new Vue({
data
})
Am I wrong in assuming that ES6's const
and let
should be standard? Is there a reason to use var
for Vue.js? Is there an issue with ES6?
Every tutorial and code snippet I'm looking at while learning the framework all use var
for their declarations, including the official docs.
Preface, I'm just starting to learn Vue, so I know very little about it, but haven't found an answer yet.
Same with other like assuming property name:
new Vue({
data: data
})
vs.
new Vue({
data
})
Am I wrong in assuming that ES6's const
and let
should be standard? Is there a reason to use var
for Vue.js? Is there an issue with ES6?
- I would assume that its because that you would need an ES6 patible piler for the interpreter to handle those things. Vue wants to get people working JS straight in without necessary setup. Whether this is what they intended is another story. – Olufemi Adesina Commented Mar 13, 2019 at 22:27
- doesnt Vue leverage babel and if so, doesnt it get converted to the correct syntax anway – Flame Commented Mar 13, 2019 at 22:30
2 Answers
Reset to default 13Why do the docs use var
and avoid ES6 features? I'd say to support lowest mon denominator, ie, worst browser.
Since Vue can be included as a plain old <script>
tag (UMD / global, no build system) and supports all ES5-pliant browsers (IE9+), they keep the documentation consistent.
Use whatever you...
- Feel fortable using, and
- Is supported by the target production environment
- your build system (if you're using one) can help transpile ES6 code to a lower language level
Besides the lowest mon denominator arguments I would like to point that var
and let
have different semantics.
When using var
variables are function scoped and they get hoisted. When using let
they are blocked scoped and they don't get hoisted.
So even if let
and const
are standard they (probably) won't replace var
any time soon.
本文标签: javascriptWhy use the var keyword in VuejsStack Overflow
版权声明:本文标题:javascript - Why use the `var` keyword in Vue.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741500154a2382020.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论