JavaScriptの継承について。
この前買った本を読んでいたら、
function initializeBase(derive, base, baseArgs) { base.apply(derive, baseArgs); for(var prop in base.prototype) { var proto = derive.constructor.prototype; if(!proto[prop]) { proto[prop] = base.prototype[prop]; } } } var Member = function(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; }; Member.prototype.getName = function() { return this.firstName + ' ' + this.lastName; }; var SpecialMember = function(firstName, lastName, role) { initializeBase(this, Member, [firstName, lastName]); this.role = role; }; SpecialMember.prototype.isAdministrator = function() { return (this.role == 'Administrator'); }; var mem = new SpecialMember('Kotaro', 'Haynes', 'Administrator'); document.writeln('Name: ' + mem.getName() + '<br>'); document.writeln('Administrator: ' + mem.isAdministrator());
3行目の"derive.constructor.prototype"で、なぜconstructorが入るのかがいまいちよく分からない。
僕の頭の中ではconstructorとprototypeは全く違うものだと思っていたからだ。