Vi Veri Veniversum Vivus Vici
На блоге Ed Spencer в посте о его взглядах на микшины в старых версиях ExtJS дана ссылка на блог другого программиста и его статью Injecting Traits into Javasсript Objects. Спасаю ее здесь:
Duplication is the mother of all evil in programming. Remaining DRY at all costs should be your goal at all times. A pattern repeats itself one time and your code complexity goes up exponentially.
One great way to DRY up your code is via Traits. Traits are functional equivalent of base classes where you can collect most often used functions and inject these Traits into your objects. Here’s one simple way to do it in Javasсript (using extjs here):
Duplication is the mother of all evil in programming. Remaining DRY at all costs should be your goal at all times. A pattern repeats itself one time and your code complexity goes up exponentially.
One great way to DRY up your code is via Traits. Traits are functional equivalent of base classes where you can collect most often used functions and inject these Traits into your objects. Here’s one simple way to do it in Javasсript (using extjs here):
MyTrait = { xhr: function(config) { return Ext.Ajax.request(config) }, submit: function(basic_form,config) { //perform some checks on config // and call basic_form.submit }, //...add more utility functions } function MyGrid(config) {MyGrid.superclass.constructor.call(this,config)} Ext.extend(MyGrid, Ext.grid.GridPanel, MyTrait);