Comments (5)
For me it's because I'm used to reading code from top to bottom, and I'm used to seeing what is exported by looking at the bottom of a file. This is a really common pattern in JS, particularly in NodeJS applications. Also, we think it makes more sense (at least to us) to have the definitions of the functions that are to be exported before the export of them.
from angularjs-style-guide.
Adding to this, having exports at the bottom fit with how you usually structure public/private code. So you will put your private functions and variables at the top, then re-use them in public functions. Having public exports at the top would work if you are using function declarations, but not work for variables/func expressions, so you will then end up having private variables followed by public exports and then private function declarations. It's just a bit easier to reference undeclared variables/functions.
from angularjs-style-guide.
Just one more question. Do you think there's a problem with having too many private variables in a class and if so would something that encourages you to use fewer of them be a good thing? That was a point made in the other conversation supporting the placement of the return at the top after a preferably short list of private vars.
from angularjs-style-guide.
Interesting point, never really thought about it that way tbh. We have generally just kept a limit on the length of our functions.
from angularjs-style-guide.
Do you think there's a problem with having too many private variables in a class and if so would something that encourages you to use fewer of them be a good thing?
Personally I don't think so - I'd rather a module have lots of private and fewer public than the other way round. Generally if a module is doing too much that will be apparent by it exposing way too many things that are often only tangentially related.
from angularjs-style-guide.
Related Issues (15)
- Why are you opposed to tools like ng-annotate? HOT 4
- Angularjs best ways of making apps compared, including this one HOT 1
- Any Demo App Using this Style? HOT 1
- Why one module per file? HOT 6
- Production HOT 6
- import angular HOT 1
- Inject ready data for directive-controllers HOT 22
- index.html HOT 3
- [Question] How do you mix many attribute directives in the same element? HOT 1
- Not loading data in the controller HOT 3
- route state resolve calling once HOT 1
- Where should I put angular.filter ? HOT 1
- Using 'replace' for a directive is being deprecated HOT 1
- Use standard facilities or reference external dependencies used in the examples HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angularjs-style-guide.