Calling the Constructor with the Apply Function
Understand how to use JavaScript's apply function to call constructors with any number of arguments in Marionette.js. Learn the technique to create new instances that correctly invoke the original constructor using a proxy, enhancing flexibility in handling model and collection storage.
We'll cover the following...
We'll cover the following...
When calling the original constructor, we pass in the first two original arguments:
var NewConstructor = function(){var obj = new OldConstructor(arguments[0], arguments[1]);// code truncated for brevity};
Passing the original arguments (assets/js/apps/config/storage/localstorage.js)
We can get away with this because we know exactly how our configureStorage function will be used—to configure local storage for models and collections. Luckily, both have two arguments in their constructor signature, so passing on two arguments to the ...