Skip to content

Instantly share code, notes, and snippets.

@anasnakawa
Last active December 22, 2015 05:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anasnakawa/6422635 to your computer and use it in GitHub Desktop.
Save anasnakawa/6422635 to your computer and use it in GitHub Desktop.
OOP in javascript extracted from CoffeeScript
// tiny JavaScript inheritance
// extracted from CoffeeScript
//
// * **param:** {Class} child
// * **param:** {Class} parent
var extends = function( child, parent ) {
for ( var key in parent ) {
if ( {}.hasOwnProperty.call( parent, key ) ) {
child[ key ] = parent[ key ];
}
}
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor();
child.__super__ = parent.prototype;
return child;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment