File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,41 @@ var quoteRegExp = function(str) {
10
10
return ( str + '' ) . replace ( / ( [ . ? * + ^ $ [ \] \\ ( ) { } | - ] ) / g, '\\$1' ) ;
11
11
} ;
12
12
13
+ var hook = { } ;
14
+
15
+ /**
16
+ * Wraps `method` on `self` so that `fn`
17
+ * is invoked before the original method.
18
+ *
19
+ * @param {object } self
20
+ * @param {string } method
21
+ * @param {function } fn
22
+ */
23
+ hook . before = function ( self , method , fn ) {
24
+ var original = self [ method ] ;
25
+ self [ method ] = function ( ) {
26
+ fn . apply ( self , arguments ) ;
27
+ return original . apply ( self , arguments ) ;
28
+ } ;
29
+ } ;
30
+
31
+ /**
32
+ * Wraps `method` on `self` so that `fn`
33
+ * is invoked after the original method.
34
+ *
35
+ * @param {object } self
36
+ * @param {string } method
37
+ * @param {function } fn
38
+ */
39
+ hook . after = function ( self , method , fn ) {
40
+ var original = self [ method ] ;
41
+ self [ method ] = function ( ) {
42
+ var result = original . apply ( self , arguments ) ;
43
+ fn . apply ( self , arguments ) ;
44
+ return result ;
45
+ } ;
46
+ } ;
47
+
13
48
var once = function ( fn ) {
14
49
var called = false ;
15
50
return function ( ) {
You can’t perform that action at this time.
0 commit comments