![]() ![]() “Code linting” is the process of automatically checking your code for common errors or style problems. A popular option that we recommend is the Airbnb style guide with the ES6 extensions (and optionally React extensions). We recommend choosing and sticking to a JavaScript style guide and enforcing it with tools. You can also read more about ES2015 and how to get started with it on the Meteor Blog: This means you can rely on runtime features like Array#forEach without worrying about which browsers support them.Īll of the code samples in this guide and future Meteor tutorials will use all of the new ES2015 features. To get the full experience, you should also use the es5-shim package which is included in all new apps by default. See the list of all ES2015 features supported by the ecmascript package. The ecmascript package is included in all new apps and packages by default, and compiles all files with the. We’ve put a lot of effort into making advanced browser features like source maps work great with this package, so that you can debug your code using your favorite developer tools without having to see any of the compiled output. It’s fully backwards compatible to “regular” JavaScript, so you don’t have to use any new features if you don’t want to. Meteor’s ecmascript package compiles this standard down to regular JavaScript that all browsers can understand using the popular Babel compiler. The newest complete standard is ES2015, which includes some long-awaited and very significant improvements to the JavaScript language. Here are our recommendations about how to use ES2015 JavaScript in your app today.Īn example of refactoring from JavaScript to ES2015 Use the `ecmascript` packageĮCMAScript, the language standard on which every browser’s JavaScript implementation is based, has moved to yearly standards releases. JavaScript is constantly improving, and the standards around ES2015 have really brought together the JavaScript community. Here at Meteor, we strongly believe that JavaScript is the best language to build web applications, for a variety of reasons. This means you can jump right into coding without learning about all of the edge cases of JavaScript ahead of time.Īs you write more code and come up against the recommended style rules, you can take that as an opportunity to learn more about your programming language and how different people prefer to use it. ![]() Using a community-recommended coding style with automatic linting can warn you about these pitfalls proactively. For example, programmers new to JavaScript often struggle with the var keyword and function scope. It’s hard to learn everything about a programming language at once. Also, by enforcing that all variables are declared before use, you can catch typos before even running any code! Deeper understanding That means you can avoid bugs where variables act in unexpected ways. For example, if you adopt a convention that you must always use let or const instead of var, you can now use a tool to ensure all of your variables are scoped the way you expect. Having a consistent style means that it’s easier to adopt standard tools for error checking. This code is misleading because it looks like both statements One example of this is indentation - while in JavaScript, indentation is not meaningful, it’s helpful to have all of your code consistently indented so that you don’t need to read all of the brackets in detail to see what is going on. If the style of every bit of code is consistent, that ensures that bits of code that look the same actually are the same - there isn’t any hidden punctuation or gotchas that you don’t expect, so you can focus on understanding the logic instead of the symbols. Mostly you just look at the shape of a certain expression, or the way it highlights in your editor, and assume what it does. The same way that you don’t read English sentences one word at a time, you don’t read code one token at a time. These benefits also apply to the Meteor and JavaScript development communities as a whole. While it’s not necessarily important whether your code base uses single or double quotes for string literals, there are huge benefits to making that decision once and having it be consistent across your organization. These are all questions that have at best a tangential relationship to code quality, but are very easy to have opinions about because they are so visual. ![]() ![]() double quotes, where to put brackets, how many spaces to type, and all kinds of other cosmetic code style questions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |