Показать сообщение отдельно
  #9 (permalink)  
Старый 14.11.2012, 19:49
Аспирант
Отправить личное сообщение для bFree Посмотреть профиль Найти все сообщения от bFree
 
Регистрация: 19.08.2008
Сообщений: 42

Обертка вот:

function Class( a, b ) {
	var description = b || a,
		superClass = b ? a : null,
		overname = Class.overname || 'super',
		Constructor = (description.name)
			? eval( "(function " + description.name +
			"(){ if ( this.__construct__ )  return this.__construct__.apply( this, arguments )})" )
			: function () {
			if ( this.__construct__ )  return this.__construct__.apply( this, arguments )
		},
		Object = function Object() {
		};

	Object.prototype = superClass ? superClass.prototype : Class.prototype;
	description.prototype = new Object;
	Constructor.prototype = new description( Constructor, description.prototype );

	var obj = Constructor.prototype;
	for ( var key in obj ) {
		if ( obj.hasOwnProperty( key ) && obj[key] instanceof Function ) {
			var parentProperty = description.prototype[key];
			if ( parentProperty )
				(function ( originalMethod, parentMethod, key ) {
					obj[key] = function () {
						var bk = this[overname];
						this[overname] = parentMethod;
						var returns = originalMethod.apply( this, arguments );
						if ( bk ) this[overname] = bk;
						else delete this[overname];
						return returns;
					}
				})( obj[key], parentProperty, key )
		}
	}

	Constructor.create = function ( args ) {
		function Object() {
			if ( this.__construct__ )  return this.__construct__.apply( this, args )
		}

		Object.prototype = Constructor.prototype;
		return new Object
	};

	return Constructor;
}
Ответить с цитированием