/* Функция создания пустого класса*/ var MakeClass = function(){ return function( args ){ if( this instanceof arguments.callee ){ if( typeof this.__construct == "function" ) this.__construct.apply( this, args ); }else return new arguments.callee( arguments ); }; } /*Функция создающая и заполняющая класс.*/ var NewClass = function( variables, constructor, functions ){ var retn = MakeClass(); for( var key in variables ){ retn.prototype[key] = variables[key]; } for( var key in functions ){ retn.prototype[key] = functions[key]; } retn.prototype.__construct = constructor; return retn; } /*Пример создания класса*/ var MyClass = NewClass( { /*Список переменных*/ "Variable1": 'I,m is variable number one!', "Variable2": 'I,m is variable number two!' }, function( x, y ){/*Функция конструктор класса*/ this.x = x; this.y = y; alert( this.Variable2 ); this.show(); },{/*Методы класса*/ "show": function(){ alert( this.Variable1 ); alert( "x = " + this.x + ", and y = " + this.y ); }, "increase": function( x, y ){ this.x += x; this.y += y; } }); /*Тест работы примера.*/ var test1 = MyClass( 1, 1 ); test1.increase( 10, 20 ); test1.show(); var test2 = MyClass( 10, 10 ); test1.show();