Decorator.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.lang.oo.Decorator"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.lang.oo.Decorator"] = true;
  8. dojo.provide("dojox.lang.oo.Decorator");
  9. (function(){
  10. var oo = dojox.lang.oo,
  11. D = oo.Decorator = function(value, decorator){
  12. // summary:
  13. // The base class for all decorators.
  14. // description:
  15. // This object holds an original function or another decorator
  16. // object, and implements a special mixin algorithm to be used
  17. // by dojox.lang.oo.mixin.
  18. // value: Object:
  19. // a payload to be processed by the decorator.
  20. // decorator: Function|Object:
  21. // a function to handle the custom assignment, or an object with exec()
  22. // method. The signature is:
  23. // decorator(/*String*/ name, /*Function*/ newValue, /*Function*/ oldValue).
  24. this.value = value;
  25. this.decorator = typeof decorator == "object" ?
  26. function(){ return decorator.exec.apply(decorator, arguments); } : decorator;
  27. };
  28. oo.makeDecorator = function(decorator){
  29. // summary:
  30. // creates new custom decorator creator
  31. // decorator: Function|Object:
  32. // a function to handle the custom assignment,
  33. // or an object with exec() method
  34. // returns: Function:
  35. // new decorator constructor
  36. return function(value){
  37. return new D(value, decorator);
  38. };
  39. };
  40. })();
  41. }