[su_icon_text icon=”icon: info-circle” icon_color=”#5b63df” class=”saki-info-box”]Code in this post can be obsolete, however, principles and theory may still apply.[/su_icon_text] You know, I’m not very big fan of factory functions, nevertheless, I’m aware of the fact that they may be necessary in some situations. Here is the file pattern that works (briefly tested).
Keep each factory function in a separate file name of which should be Namespace.Factory.functionName.js
// vim: ts=4:sw=4:nu:fdc=4:nospell /*global Ext, MyNamespace */ /** * @class MyNamespace.Factory * * A Factory function pattern * * @author Ing. Jozef Sakáloš * @copyright (c) 2009, by Ing. Jozef Sakáloš * @date 17. March 2009 * @version 0.1 * @revision $Id$ * * @license MyNamespace.Factory.myPanel.js is licensed under the terms of * the Open Source LGPL 3.0 license. Commercial use is permitted to the extent * that the code/component(s) do NOT become part of another Open Source or * Commercially licensed development library or toolkit * without explicit permission. * * * License details: http://www.gnu.org/licenses/lgpl.html */ // create namespace Ext.ns('MyNamespace.Factory'); /** * @method myPanel * @param {Object} config * A config object * @return {Ext.Panel} */ MyNamespace.Factory.myPanel = function(config) { // pre-instantiation code var defaults = { // put your defaults here // but avoid id, el, contentEl, renderTo, applyTo, or similar }; // eo defaults object // create config object var cfg = Ext.apply({}, config, defaults); // instantiate var cmp = new Ext.Panel(cfg); // post-instantiation code // return the created component return cmp; } // eo function MyNamespace.Factory.myPanel // eof
I'm a well seasoned developer, consultant and educator of web applications based mainly on Sencha libraries, PHP, MySQL and Node.js. Besides (Apple) computers, I love photography and mountain biking.
Follow me:
Latest posts by saki (see all)
- Ext, Angular, React, and Vue - 27. June 2019
- The Site Resurgence - 11. February 2018
- Configuring ViewModel Hierarchy - 19. June 2015