Sha256: fb20f8f510a5759c6b929cf604cbe9276446fa258929995c3239fa1fc773b9ca

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

JS.Decorator = new JS.Class('Decorator', {
  initialize: function(decoree, methods) {
    var decorator  = new JS.Class(),
        delegators = {},
        method, func;
    
    for (method in decoree.prototype) {
      func = decoree.prototype[method];
      if (JS.isFn(func) && func !== decoree) func = this.klass.delegate(method);
      delegators[method] = func;
    }
    
    decorator.include(new JS.Module(delegators), false);
    decorator.include(this.klass.InstanceMethods, false);
    decorator.include(methods, true);
    return decorator;
  },
  
  extend: {
    delegate: function(name) {
      return function() {
        return this.component[name].apply(this.component, arguments);
      };
    },
    
    InstanceMethods: new JS.Module({
      initialize: function(component) {
        this.component = component;
        this.klass = this.constructor = component.klass;
        var method, func;
        for (method in component) {
          if (this[method]) continue;
          func = component[method];
          if (JS.isFn(func)) func = JS.Decorator.delegate(method);
          this[method] = func;
        }
      },
      
      extend: function(source) {
        this.component.extend(source);
        var method, func;
        for (method in source) {
          func = source[method];
          if (JS.isFn(func)) func = JS.Decorator.delegate(method);
          this[method] = func;
        }
      }
    })
  }
});

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
spontaneous-0.1.0.alpha1 application/js/vendor/JS.Class-2.1.5/src/decorator.js
acts_as_dashboard-0.4.1 generators/dashboard/templates/js.class-2.1.4/src/decorator.js
acts_as_dashboard-0.4.0 generators/dashboard/templates/js.class-2.1.4/src/decorator.js
acts_as_dashboard-0.3.3 generators/dashboard/templates/js.class-2.1.4/src/decorator.js
acts_as_dashboard-0.3.2 generators/dashboard/templates/js.class-2.1.4/src/decorator.js
acts_as_dashboard-0.3.0 generators/dashboard/templates/js.class-2.1.4/src/decorator.js
acts_as_dashboard-0.1.0 generators/dashboard/templates/js.class-2.1.4/src/decorator.js