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):

  1. MyTrait = {
  2. xhr: function(config) { return Ext.Ajax.request(config) },
  3. submit: function(basic_form,config) {
  4. //perform some checks on config
  5. // and call basic_form.submit
  6. },
  7. //...add more utility functions
  8. }
  9. function MyGrid(config) {,config)}
  10. Ext.extend(MyGrid, Ext.grid.GridPanel, MyTrait);

@темы: ExtJS