Answer the question
In order to leave comments, you need to log in
Can you please explain how the new operator is used here?
The marionette documentation has this example:
MyApp.addInitializer(function(options){
new MyAppRouter();
Backbone.history.start();
});
Answer the question
In order to leave comments, you need to log in
This is just a whim of the author of the documentation. This example is taken from the documentation for Marionette.Application and it demonstrates how initializers work. Here the link to the router itself is not needed, because the router instance is created in this way.
But even this code is absolutely working, since usually the only task of the router is to respond to a change in the route. And the binding of these changes just happens when the constructor is called.
1. The person who wrote the documentation did not consider it necessary that the router object would ever be needed, so they did not write it to a variable.
2. The MyAppRouter instance is created in memory only.
3. Access to the created object cannot be obtained (at least publicly).
4. In this case, the main logic of the MyAppRouter class is contained in the constructor, so no method of this class needs to be called in the future (according to the author's idea).
5. In general, this is a bad example, in practice it is not good to do this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question