문제

During research into architecture of single page applications, I came across the following resource by Mikito Takada, written around 2013: http://singlepageappbook.com/

In his introduction he distinguishes between architecture (conceptual parts of the application including the view and model) and asset packaging (how the application is divided into files and modules). In the context of discussing asset packaging, he mentions fully traversable namespaces as an example of bad packaging practice.

I would guess this phrase described a situation where all code could access all code. However he also separately mentions global code and global names as examples of bad practice, leaving me struggling to differentiate between global code and fully traversable namespaces.

Would anybody be kind enough to define what is meant by a fully traversable namespace or generally correct my understanding of these terms?

Thankyou

도움이 되었습니까?

해결책

From reading the cited work I think you are right in assuming the authour is referring to global namespaces as bad practice and they are using fully traversable namespaces as an example of something you should not do as it is under the column "Messy and random".

I have not heard this term before and the book does not specify exactly what it is supposed to mean.

I would say that the point they are trying to make is that you can get at all aspects of the program, functions and variables of an object and its prototype object from anywhere else. In Java there is the idea of access modifiers with public, private, package protected, and protected modifiers that limit module's access to other parts of the program. Javascript doesn't handle access this way.

The authour states that by using the Javascript Global object "Every piece of code is made global by default" and contrasts this with "Implementation details are inaccessible outside the package". I believe this is a bit misleading as Javacsript functions do provide a new scope and do not expose 'every piece of code'.

Javascript uses the block syntax, but unlike other languages that enclose blocks of code within braces, Javascript does not limit scope to within these sections. The generic advise of declaring variables as close to the code that will use it becomes a problem in Javascript. You can limit scope within Javascript functions and modules.

The main point the authour is trying to make is good; when using Javascript be careful to understand what scope your variables are in, and partitioning your code into sensible units is a good idea for readability / maintainability.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 softwareengineering.stackexchange
scroll top