This is a piece of project code. $this[‘config’] has a ECMAScript assigned to it, but actually new has a new object. What is the difference between writing this way and writing a new object directly? Or what are the advantages?
Class in screenshot
CashierIt is a Service Container. In short, if you directly
new Config($config), then instantiate
CashierWhen, will inevitably create
ConfigExamples, whether used or not. Using closures only gives access dependencies (i.e.
ConfigInstance), so that instantiation will only be called when needed.
For the practice of using closures to handle dependency injection, please refer to this article:http://fabien.potencier.org/o ….