ES "let's you work around this" in that it let's you just do stupid shit until it blows up in your face. Statically typed languages force you to consider those scenarios that might lead to blow ups. You still have to consider those scenarios in ES, but the language doesn't force you to, so you have to have the diligence to do it yourself.
"Expressiveness" doesn't mean "write as little code as possible to get the base case running". Expressiveness means the ability to implement different patterns of solutions with native syntax. C++ is "more expressive" than C when it comes to object oriented programming, not because C cannot do OO, but because C++ has specific, checked syntax for it.
References are consistent and one-way, you no longer have to deal with searching for where a given dependency is coming from... Or where the implementation is... references are always direct this way.
C#: using MyOrg.Base.Interfaces;
public class Foo {
public IBar Bar {get;set;}
public string Baz() {
//wth is IBar.Baz implementation come from?
//damn, now I need to search the project for IBar
return this.Bar.Baz(this);
}
}
JS import bar from '../lib/bar';
export default function baz(context) {
return bar.baz(context);
}
In the JS case, you know where the implementation of bar comes from when looking into code, trying to resolve a bug. You can also use proxyquire in order to test the module, replacing bar with a shim for the purposes of testing... in the JS case the code is still clean, and you don't have a couple of layers of indirection abstracting you away from finding the next piece in the puzzle. And it doesn't limit your ability to test.And I don't know what that last part is supposed to mean. I've never not know "where my dependencies are coming from" or "where the implementation is". It's not like they live in some hidden place that I can't access. I reference them directly and explicitly.
EDIT: you ninja-edited on me. No, you are not at a loss for where IBar is defined. It's extremely easy--a single key press--to find it. Just hit F12 on it. You'll go right to its definition.
I'm not saying these patterns should never be used... only that there are generally simpler expressions that should usually be favored.
I think people forget that, in JS, the types still exist. Just because it's not statically typed doesn't mean you don't have to think about types and what types are appropriate for given scenarios.
With JS, it's impossible to tell just from inspecting a reference to a function what it expects from you and what you can expect to give back. You have the length property to tell you the number of arguments and that's it. Of course, that's assuming it's not using a variadric arguments pattern, in which case the length value only tells you the minimum number of parameters expected, but not that more are possible.
Even if you can make reasonable assumption about the number of parameters, you won't be able to tell at all what types the function expects for those parameters. Want to list all the functions in a class that take two numbers and return a different number? Can't do it.
But still, if you could make reasonable assumptions about the type of things that go in and out of the function, you won't know how to even call the function. Does the function expect to be called as a method of a class? Does it expect to be called as a static function? The best you can hope for is to toString the function and check if the source includes the word "this". Here's hoping it's one written in JS itself and not one that is implemented internally in the browser.
Now before anyone says "why would you ever need anything like that?", it's an absolute necessity for building any sort of user-driven or data-driven reporting system. You need to be able to tell when your data set matches the functions you want to apply to them, at run-time, because the data isn't available at design-time. It's the classic reflection use case.
As far as I'm concerned, safety-guaranteed reflection is impossible in JS, unless you throw away JS functions almost completely and create your own Functor class with all the extra type information that you would need.
For that matter, you can use an object stream, and pipe it all through to resolution. If your data comes from variant sources (spreadsheets, dirty xml, etc) then you are way better off with a scripted language.
Try importing a WSDL that defines various interfaces to use "Object" and VS/.Net chokes on it.
As far as users go, without the hard enforcements you can coerce values into either what you expect or cleanly drop out... unlike .Net where you have to go through the Try versions of convert, on who knows how many types in order to get something resembling predictable values... that doesn't even include regular expression syntax as a first class concept in JS.
I've handled dynamic input sources from both .Net (VB.Net and C#) and I'll tell you that most of the time JS/Node is simply easier... I've replaced complex importers written in .Net with straight forward, easy to reason with JS importers that run in Node, and edit/run/deploy without a compile step.
I will say that I do like that VB.Net has XML literals which can be very useful... but now that JSON is getting to be more common JS is less of a disconnect.
The things you're talking about doing, they are bad software design.
JS doesn't even come close to the expressiveness that you get in C# due to the fact that in JS, you don't even know the type of arguments being passed in any given function without looking elsewhere in the code - therefore, it's not easy to understand.
If you're going to go with the definition that says expressiveness means "the variety and quantity of ideas that can be expressed", Javascript also loses there since there are whole classes of behavior that cannot be practically expressed in Javascript. For instance - try writing a function that only accepts a standard single precision floating-point number as it's argument and see how much work you have to do compared to other languages.
Try expressing a Dictionary, Linked List, HashTable, SortedList, SortedDictionary, etc in JS - you'll be writing those structures yourself or cobbling together some random lib. Better languages let you actually express those things without having to write them yourself.
Don't get me wrong here, I like a LOT about C# but expressiveness compared to JS doesn't even come close, when you include the pending ES7 stuff via Babel.