TypeScript also supports what are known as "definition files". These are a lot like C headers. They define objects and types and method signatures, often belonging to libraries outside of your control. We use them when coding against dojo, the ArcGIS JavaScript API, and jQuery. They are simply code contracts. They tell us what's available, and how to create objects and call methods upon them without making mistakes and wasting time.
Dynamic typing is one of the core concepts of JavaScript, which is powerful. Which one is better is arguable. But since JavaScript has dynamic typing nature, I'm not sure if adding a typescript upon it makes a lot of sense. I haven't compared the performance of typescript. But JavaScript normally has the reputation of "SLOW", you may not want to sacrifice more just for type safe. Once you get used to dynamic typing, you will find it's a very flexible and interesting feature.
// JavaScript: var thing = "a b c"; thing = 5; // Totally fine! var pieces = thing.split(" "); // Run time error: thing.split is not function
// TypeScript: var thing = "a b c"; thing = 5; // Compile time error: Type of "thing" is string, not number! var pieces = thing.split(" ");
...To your last point, about "single responsibility principle for the scope of require([])", I think the answer is yes, if I understand correctly. Typically, in things that I build, I create classes (one per AMD module) and then wire them up with a main.js or app.js file which contains a single require(). I don't typically put anything in the global namespace except when debugging. If I find myself with a huge list of dependencies for any require() or define() call, I take that as a sign that it's probably time to refactor and that I'm trying to do too much at one time.
If I find myself with a huge list of dependencies for any require() or define() call, I take that as a sign that it's probably time to refactor and that I'm trying to do too much at one time.
We recommend using Dojo's tools for creating classes and modules to manage your code when you start building large apps. Our Dojo and AMD page is the best place to start. You'll find links to writing classes and widgets from there.Regarding MVVM, we don't typically recommend MVVM, MVC or any other flavor of MVW (model-view-whatever). You can use any MVW framework alongside our API, including Backbone, Angular, Ember...the list goes on. Here's a repo that Matt Driscoll and I put together for examples using Backbone, Angular and Knockout at the Esri Dev Summit earlier this year: https://github.com/driskull/framework-samples-jsTo your last point, about "single responsibility principle for the scope of require([])", I think the answer is yes, if I understand correctly. Typically, in things that I build, I create classes (one per AMD module) and then wire them up with a main.js or app.js file which contains a single require(). I don't typically put anything in the global namespace except when debugging. If I find myself with a huge list of dependencies for any require() or define() call, I take that as a sign that it's probably time to refactor and that I'm trying to do too much at one time.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.