@@ -176,8 +176,7 @@ class Registry {
176
176
cloned = object ;
177
177
console . warn ( "Could not clone object:" , error ) ;
178
178
}
179
- checkForClashingFunctions ( cloned , instantiated ) ;
180
- instantiated = Object . assign ( instantiated , cloned ) ;
179
+ assign ( instantiated , cloned ) ;
181
180
instantiated . init ? instantiated . init ( ) : { } ; //Initialise if possible.
182
181
return instantiated ;
183
182
}
@@ -202,16 +201,27 @@ class Registry {
202
201
203
202
let hasNonAscii = ( str ) => [ ...str ] . some ( ( char ) => char . charCodeAt ( 0 ) > 127 ) ;
204
203
205
- function checkForClashingFunctions ( source , target ) {
206
- for ( let prop in source ) {
207
- if ( prop in target ) {
208
- if ( typeof target [ prop ] === "function" ) {
209
- throw new SyntaxError (
210
- "Property '" + prop + "' clashes with a class method!"
211
- ) ;
212
- }
204
+ /**A version of `Object.assign()` which only copies keys present on both objects, and will not allow functions to be overridden.\
205
+ * Mutates the original object, and returns it.
206
+ */
207
+ function assign ( target , source ) {
208
+ for ( let key of Object . getOwnPropertyNames ( source ) ) {
209
+ let value = source [ key ] ;
210
+ let replace = target [ key ] ;
211
+ if ( replace !== undefined ) {
212
+ if ( typeof replace !== "function" ) {
213
+ target [ key ] = value ;
214
+ } else console . warn ( "Cannot replace an object's method: " + key ) ;
215
+ } else {
216
+ console . warn (
217
+ "Cannot create properties using `construct()`-derived functions: " +
218
+ key +
219
+ " is not present on type " +
220
+ target . constructor . name
221
+ ) ;
213
222
}
214
223
}
224
+ return target ;
215
225
}
216
226
217
227
export { Registry } ;
0 commit comments