Closed etlolap closed 10 years ago
I noticed this was also asked over at http://stackoverflow.com/questions/19416520/javascript-this-superclass-constructor-and-extend :) The extend()
found here is not part of jQuery nor built into JavaScript itself but was meant to symbolically represent object extension. superclass
is a property of this
as mentioned, but also needs to be made more clear. That was a failure on my part. Let's fix it!
Going to rewrite this sample to be more clear.
Clarifications and a running example added. Please let me know if these aren't clear!
Addy,
These codes were extracted from your example for abstract decorator. I got confused by this.superclass.constructor() and extend().
I can understand this refers to myMacbookPro, an instance of CaseDecorator here. But what does this.superclass refer? Why not just this.constructor(macbook)?
CaseDecorator's superclass is MacbookDecorator? Where did the inheritance happen? Are they part of native Javascript or an 3rd party library?
Thanks
var CaseDecorator = function( macbook ){
// call the superclass's constructor next this.superclass.constructor( macbook );
};
// Let's now extend the superclass extend( CaseDecorator, MacbookDecorator ); .... // Decorate the macbook myMacbookPro = new CaseDecorator( myMacbookPro );