Why were namespaces excluded from ECMAScript?

Namespaces were once considered for ECMAScript (old ECMAScript 4), but were exported. As Brendan Eich says in this post :

One of the options for using namespaces in ES4 was early binding (use of the namespace is internal), both for performance and for the programmer to understand - there is no likelihood of binding the run-time name to disagree with previous bindings. But early binding in any dynamic code loading scenario, such as the Internet, requires prioritization or a reservation mechanism to avoid early vs. late connected conflicts.

Plus, as some JS developers have noted with concern that multiple public namespaces impose runtime costs, except when doing work
much more complicated.

For these reasons, namespaces and early binding (for example, packages before they, last April) should go.

But I'm not sure I understand all this. What is a prioritization or reserving mechanism and why is any of them necessary? Also, do you need early binding and namespaces go hand in hand? For some reason I can't wrap my head around problems. Can someone try to explain a more detailed explanation?

Also, why do namespaces impose runtime costs? In my opinion, I cannot help but see a slight difference in concept between the namespace and the function using closures. For example, Yahoo and Google have YAHOO and google objects that act as namespaces because they contain all of their public and private variables, functions, and objects within a single access point. So, why then will the namespace differ significantly in implementation? Maybe I have a misconception about what a namespace is.

For the sake of generosity, I would like to know two things:

  • Is namespace binding required early?
  • How is the implementation of the namespace implementation different from the object private members?
+7
javascript namespaces ecma262 language-design
source share
2 answers

If you declare a variable in closure after the function definition calls this variable, it still uses the scope variable.

function ShowMe() { alert(myVar); //alerts "cool" } var myVar = "cool"; 

This process will get another level of complexity with respect to the namespace.

In addition, there are numerous namespace methods along with expand / applyIf, etc., which can perform many functions. namespace () in ExtJS or $ .extend in jQuery, for example. Thus, it may be nice to have, but it is not an absolute need for language constructs. I believe that formalizing some extensions for Array and supporting ISO-8601 dates in Date is much more important. To just check every namespace layer to determine ...

 window.localization = $.extend(window.localization || {}, { ... }); window.localization.en = $.extend(window.localization.en || {}, { ... }); 
+2
source share

OK first. Some terms:

  • Early binding - validation / validation when a line of code is parsed.
  • Late binding - validation / validation when a line of code is executed.
  • Prioritization / reservation - I think they mean that if you do early binding and check namespaces when analyzing the code, there should be a process of checking the variable name when the variable is added dynamically later, and a different set of rules for what is valid since this point may have several areas.

I am sincerely surprised that only these rather technical reasons were given. Take the general case: -

 onclick=' var mymark = "donethat";' 

What namespace should belong to "mymark"? There seems to be no easy answer to this question. Especially considering the code snippet: -

 window.forms.myform.mybutton.onClick = ' var mymark = "donethat";' 

Must put the variable in the same namespace.

+1
source share

All Articles