xb.core.object = function() { if ( this.__proto__ === arguments.callee.prototype ) { this.ctor(); } else { return new xb.core.object(); } } xb.core.object.stir = function( proto, object ) { if ( typeof( proto ) !== "undefined" && typeof( proto.ctor ) === "function" ) { var mixins = proto.mixins; if ( ( mixins instanceof Array ) && mixins.length ) { for ( var i = 0, il = mixins.length; i < il; i++ ) { if ( typeof( mixins[ i ].prototype.stir ) === "function" ) { mixins[ i ].prototype.stir.call( object ); } } } xb.core.object.stir( proto.__proto__, object ); } } xb.core.object.extend = function( base, object ) { var mixins = []; var base = base; if ( typeof( object ) === "undefined" ) { object = base; if ( this.__xbExtended === true ) { base = this; } else { base = xb.core.object; } } else if ( base instanceof Array ) { mixins = base; base = mixins.shift(); } /* Onderstaande moet ervoor zorgen dat xb.core.object iig IN de prototype chain zit. */ if ( !( base === xb.core.object ) && !( base.__xbExtended ) && ( object !== xb.core.object ) ) { base = xb.core.object.extend( base, xb.core.object ); } mixins.push( object ); var prototype = { __proto__: base.prototype }; for ( var i = 0, il = mixins.length; i < il; i++ ) { var mixin = null; if ( typeof( mixins[ i ].prototype ) === "undefined" ) { mixin = mixins[ i ]; } else { mixin = mixins[ i ].prototype; } var properties = Object.getOwnPropertyNames( mixin ); for ( var j = 0, jl = properties.length; j < jl; j++ ) { var propName = properties[ j ]; if ( propName !== "factory" && propName !== "ctor" && propName !== "mixins" ) { prototype[ propName ] = mixin[ propName ]; } } } if ( typeof( object.ctor ) !== "undefined" ) { prototype.ctor = object.ctor; } if ( typeof( object.factory ) !== "undefined" ) { prototype.factory = object.factory; } mixins.pop(); prototype.mixins = mixins; xb.core.object.stir( prototype, prototype ); var ctorProxy = function() { var p = arguments.callee.prototype; if ( this.__proto__ === p ) { if ( typeof( ctorProxy.calledWith ) !== "undefined" ) { var arguments = ctorProxy.calledWith; ctorProxy.calledWith = undefined; } this.ctor.apply( this, arguments ); } else { ctorProxy.calledWith = arguments; var object = new ctorProxy(); return object; } }; var factoryProxy = function() { var p = arguments.callee.prototype; if ( this.__proto__ === p ) { this.ctor.apply( this, arguments ); } else { return p.factory.apply( factoryProxy, arguments ); } }; var ctor = ctorProxy; if ( typeof( prototype[ "factory" ] ) !== "undefined" ) { ctor = factoryProxy; } // prototype.constructor = ctor; ctor.prototype = prototype; ctor.extend = xb.core.object.extend; ctor.__xbExtended = true; return ctor; } xb.core.object.prototype = { ctor: function() { }, copyMixins: function( p, object ) { if ( p.mixins instanceof Array ) { for ( var i = 0, il = p.mixins.length; i < il; i++ ) { if ( typeof( p.mixins[ i ].prototype.copyMixin ) === "function" ) { // console.log( "mixin copy", i ); p.mixins[ i ].prototype.copyMixin.call( this, object ); } } this.copyMixins( p.__proto__, object ); } }, copy: function( recursive ) { var recursive = ( typeof( recursive ) !== "undefined" ); var c = {}; c.__proto__ = this.__proto__; var properties = Object.getOwnPropertyNames( this ); for ( var j = 0, jl = properties.length; j < jl; j++ ) { var propName = properties[ j ]; if ( this[ propName ] === null ) { c[ propName ] = null; } else if ( recursive === true && ( typeof( this[ propName ] ) === "object" ) ) { c[ propName ] = xb.core.object.prototype.copy.call( this[ propName ], recursive ); } else { c[ propName ] = this[ propName ]; } } if ( typeof( c.copyMixins ) === "function" ) c.copyMixins( c.__proto__, this ); return c; }, clone: function() { var c = {}; c.__proto__ = this; return c; } }