Switching between singleton and prototype scope using RequireJS
问题 Spring has very useful option, that whey I define a bean, I define a scope. If it's singleton , only one instance is created. By prototype , each time a bean is required, a new instance is created. RequireJS provides by default singletons, so with such simple module: Singleton.js define([], function() { console.log('Instance initialization') var items = [] var singleton = { getItems: function() { return items }, setItems: function(newItems) { items = newItems }, addItem: function(item) {