Skip to content

Instantly share code, notes, and snippets.

@hayeah
Created March 25, 2014 09:22
Show Gist options
  • Save hayeah/9757971 to your computer and use it in GitHub Desktop.
Save hayeah/9757971 to your computer and use it in GitHub Desktop.
coffeescript __extend helper for defining subclass
__extends = function(child, parent) {
for (var key in parent) {
if (__hasProp.call(parent, key)) child[key] = parent[key];
}
function ctor() {
// why set the prototype's constructor to child?
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor;
child.__super__ = parent.prototype;
return child;
};
@FrankFan
Copy link

Is this correct ?

@FrankFan
Copy link

what is __hasProp ?

@FrankFan
Copy link

oh, I know

var __hasProp = {}.hasOwnProperty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment