Skip to content

Instantly share code, notes, and snippets.

@edgarberm
Created July 14, 2016 15:44
Show Gist options
  • Save edgarberm/47ad5a1077cd721b0d590fb4e28f1562 to your computer and use it in GitHub Desktop.
Save edgarberm/47ad5a1077cd721b0d590fb4e28f1562 to your computer and use it in GitHub Desktop.
Copy the prototype methods of the given constructor method into the given context, if they do not already exist.
const assignPrototypeMethods = ( constructorMethod, context ) => {
// Loop over the BaseController's prototype methods and assign them to the current context
for ( var methodName in constructorMethod.prototype ) {
if (constructorMethod.prototype.hasOwnProperty( methodName ) && !context[ methodName ]) {
// Copy the method into the current controller context.
context[ methodName ] = constructorMethod.prototype[ methodName ];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment