source: Dev/branches/rest-dojo-ui/client/dojox/lang/oo/general.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.8 KB
Line 
1dojo.provide("dojox.lang.oo.general");
2
3dojo.require("dojox.lang.oo.Decorator");
4
5(function(){
6        var oo = dojox.lang.oo, md = oo.makeDecorator, oog = oo.general,
7                isF = dojo.isFunction;
8
9        // generally useful decorators
10
11        oog.augment = md(function(name, newValue, oldValue){
12                // summary: add property, if it was not defined before
13                return typeof oldValue == "undefined" ? newValue : oldValue;
14        });
15
16        oog.override = md(function(name, newValue, oldValue){
17                // summary: override property only if it was already present
18                return typeof oldValue != "undefined" ? newValue : oldValue;
19        });
20
21        oog.shuffle = md(function(name, newValue, oldValue){
22                // summary: replaces arguments for an old method
23                return isF(oldValue) ?
24                        function(){
25                                return oldValue.apply(this, newValue.apply(this, arguments));
26                        } : oldValue;
27        });
28
29        oog.wrap = md(function(name, newValue, oldValue){
30                // summary: wraps the old values with a supplied function
31                return function(){ return newValue.call(this, oldValue, arguments); };
32        });
33
34        oog.tap = md(function(name, newValue, oldValue){
35                // summary: always returns "this" ignoring the actual return
36                return function(){ newValue.apply(this, arguments); return this; };
37        });
38
39        oog.before = md(function(name, newValue, oldValue){
40                //      summary:
41                //              creates a chain of calls where the new method is called
42                //              before the old method
43                return isF(oldValue) ?
44                        function(){
45                                newValue.apply(this, arguments);
46                                return oldValue.apply(this, arguments);
47                        } : newValue;
48        });
49
50        oog.after = md(function(name, newValue, oldValue){
51                //      summary:
52                //              creates a chain of calls where the new method is called
53                //              after the old method
54                return isF(oldValue) ?
55                        function(){
56                                oldValue.apply(this, arguments);
57                                return newValue.apply(this, arguments);
58                        } : newValue;
59        });
60})();
Note: See TracBrowser for help on using the repository browser.