Slide 10
Slide 10 text
Can it inherit?
With a factory it can:
createInstance = function( constr, args, props ) {
var instance,
members = ( typeof constr === "function" ? constr.apply( constr.prototype, args || [] ) : constr ),
Fn = function () {};
xObject.mixin( members || {}, props || {} );
// Inherit from a super type if any specified in __extends__ property
if ( members.hasOwnProperty( "__extends__" ) && members.__extends__ ) {
constr.prototype = createInstance( members.__extends__, args );
}
// Copy given type prototype linking to a new constructor
Fn.prototype = constr.prototype || {};
// Mix-in members of given type to the new constructor's prototype
xObject.mixin( Fn.prototype, members );
instance = new Fn();
// Call constructor function if any specified in __constructor__ property
members.hasOwnProperty("__constructor__") &&
members.__constructor__.apply( instance, args || [] );
return instance;
};