Skip to content

Commit 995f272

Browse files
committed
Merge pull request #45 from wmde/unname
Remove broken optional debug feature
2 parents 39d1ff9 + 5e3dc5c commit 995f272

File tree

3 files changed

+12
-119
lines changed

3 files changed

+12
-119
lines changed

config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ this.config = ( function() {
226226
]
227227
},
228228
tests: [
229-
'tests/lib/util/util.inherit.tests',
230229
'tests/lib/globeCoordinate/globeCoordinate.tests',
231230
'tests/lib/globeCoordinate/globeCoordinate.Formatter.tests',
232231
'tests/lib/globeCoordinate/globeCoordinate.GlobeCoordinate.tests',

lib/util/util.inherit.js

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ this.util = this.util || {};
88
( function( util ) {
99
'use strict';
1010

11-
/**
12-
* @type {Function}
13-
*/
14-
var EMPTY_FN = function() {};
15-
1611
/**
1712
* Extends an object with the attributes of another object.
1813
*
@@ -30,32 +25,15 @@ this.util = this.util || {};
3025
}
3126

3227
/**
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.
3429
*
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.
3931
* @return {Function}
40-
*
41-
* @throws {Error} if the given name has no characters matching [\w$].
4232
*/
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() {};
5937
}
6038

6139
/**
@@ -82,7 +60,10 @@ this.util = this.util || {};
8260
util.inherit = function( name, base, constructor, members ) {
8361
// name is optional
8462
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;
8667
}
8768

8869
// allow to omit constructor since it can be inherited directly. But if given, require it as
@@ -96,19 +77,13 @@ this.util = this.util || {};
9677
constructor = false;
9778
}
9879
}
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';
10580

10681
// function we execute in our real constructor
107-
var NewConstructor = createNamedFunction( constructorName, constructor || base );
82+
var NewConstructor = createFunction( constructor || base );
10883

10984
// new constructor for avoiding direct use of base constructor and its potential
11085
// side-effects
111-
var NewPrototype = createNamedFunction( prototypeName );
86+
var NewPrototype = createFunction();
11287
NewPrototype.prototype = base.prototype;
11388

11489
NewConstructor.prototype = extend(

tests/lib/util/util.inherit.tests.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)