@@ -8,11 +8,6 @@ this.util = this.util || {};
8
8
( function ( util ) {
9
9
'use strict' ;
10
10
11
- /**
12
- * @type {Function }
13
- */
14
- var EMPTY_FN = function ( ) { } ;
15
-
16
11
/**
17
12
* Extends an object with the attributes of another object.
18
13
*
@@ -30,32 +25,15 @@ this.util = this.util || {};
30
25
}
31
26
32
27
/**
33
- * Helper to create a named function which will execute a given function.
28
+ * Helper to create a function which will execute a given function.
34
29
*
35
- * @param {string } name Name of the new function. All characters not matching [\w$] will be
36
- * removed.
37
- * @param {Function } [originalFn] Function which will be executed by new function. If not given,
38
- * an empty function will be used instead.
30
+ * @param {Function } [originalFn] Optional function which will be executed by new function.
39
31
* @return {Function }
40
- *
41
- * @throws {Error } if the given name has no characters matching [\w$].
42
32
*/
43
- function createNamedFunction ( name , originalFn ) {
44
- /* jshint evil: true */
45
- /* jshint unused: false */
46
- var namedFn ;
47
- var evilsSeed = originalFn || EMPTY_FN ;
48
- var fnName = name . replace ( / (?: ( ^ \d + ) | [ ^ \w $ ] ) / ig, '' ) ;
49
-
50
- if ( ! fnName ) {
51
- // only bad characters were in the name!
52
- throw new Error ( 'Bad function name given. At least one word character or $ required.' ) ;
53
- }
54
-
55
- eval ( 'namedFn = function ' + fnName +
56
- '(){ evilsSeed.apply( this, arguments ); }' ) ;
57
-
58
- return namedFn ; // value got assigned in eval
33
+ function createFunction ( originalFn ) {
34
+ return originalFn
35
+ ? function ( ) { originalFn . apply ( this , arguments ) }
36
+ : function ( ) { } ;
59
37
}
60
38
61
39
/**
@@ -82,7 +60,10 @@ this.util = this.util || {};
82
60
util . inherit = function ( name , base , constructor , members ) {
83
61
// name is optional
84
62
if ( typeof name !== 'string' ) {
85
- members = constructor ; constructor = base ; base = name ; name = false ;
63
+ members = constructor ;
64
+ constructor = base ;
65
+ base = name ;
66
+ name = false ;
86
67
}
87
68
88
69
// allow to omit constructor since it can be inherited directly. But if given, require it as
@@ -96,19 +77,13 @@ this.util = this.util || {};
96
77
constructor = false ;
97
78
}
98
79
}
99
- // If no name is given, find suitable constructor name. We want proper names here, so
100
- // instances can easily be identified during debugging.
101
- var constructorName = name
102
- || constructor . name
103
- || ( base . name ? base . name + '_SubProto' : 'SomeInherited' ) ,
104
- prototypeName = base . name || 'SomeProto' ;
105
80
106
81
// function we execute in our real constructor
107
- var NewConstructor = createNamedFunction ( constructorName , constructor || base ) ;
82
+ var NewConstructor = createFunction ( constructor || base ) ;
108
83
109
84
// new constructor for avoiding direct use of base constructor and its potential
110
85
// side-effects
111
- var NewPrototype = createNamedFunction ( prototypeName ) ;
86
+ var NewPrototype = createFunction ( ) ;
112
87
NewPrototype . prototype = base . prototype ;
113
88
114
89
NewConstructor . prototype = extend (
0 commit comments