Skip to content

Commit

Permalink
Using register to "fix" mangled function names, see #28
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Aug 7, 2017
1 parent d8bec6c commit 57d1efc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion js/Namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ define( function( require ) {
* @public
*/
register: function( key, value ) {
var lastKey;

// If the key isn't compound (doesn't contain '.'), we can just look it up on this namespace
if ( key.indexOf( '.' ) < 0 ) {
assert && assert( !this[ key ], key + ' is already registered for namespace ' + this.name );
this[ key ] = value;
lastKey = key;
}
// Compound (contains '.' at least once). x.register( 'A.B.C', C ) should set x.A.B.C.
else {
Expand All @@ -62,9 +64,16 @@ define( function( require ) {
}

// Write into the inner namespace, e.g. x.A.B[ 'C' ] = C
var lastKey = keys[ keys.length - 1 ];
lastKey = keys[ keys.length - 1 ];
assert && assert( !parent[ lastKey ], key + ' is already registered for namespace ' + this.name );
parent[ lastKey ] = value;

}

if ( typeof value === 'function' ) {
Object.defineProperty( value, 'name', {
value: lastKey
} );
}

return value;
Expand Down

0 comments on commit 57d1efc

Please sign in to comment.