// Объект включающий в себя функционал по проверки типов переменных.
var TypeOf = new (function()
{
{
// Строковые представления JS-типов
var m_number = (typeof 0);
var m_object = (typeof {});
var m_string = (typeof '');
var m_boolean = (typeof true);
var m_undefined = (typeof undefined);
var m_function = (typeof (function(){}));
}
{
// Если не нравится вызов методов для проверки можно использовать нижеприведенные переменные.
// Но чисто теоретически их можно изменять из вне что приведет к глюку всей программы
this.Number = m_number;
this.Object = m_object;
this.String = m_string;
this.Boolean = m_boolean;
this.Undefined = m_undefined;
this.Function = m_function;
}
{
// Методы по проверки типов переменных
this.isNumber = function(value) { return (typeof value == m_number); };
this.isNotNumber = function(value) { return (typeof value != m_number); };
this.isObject = function(value) { return (typeof value == m_object); };
this.isNotObject = function(value) { return (typeof value != m_object); };
this.isString = function(value) { return (typeof value == m_string); };
this.isNotString = function(value) { return (typeof value != m_string); };
this.isBoolean = function(value) { return (typeof value == m_boolean); };
this.isNotBoolean = function(value) { return (typeof value != m_boolean); };
this.isUndefined = function(value) { return (typeof value == m_undefined); };
this.isNotUndefined = function(value) { return (typeof value != m_undefined); };
this.isFunction = function(value) { return (typeof value == m_function); };
this.isNotFunction = function(value) { return (typeof value != m_function); };
}
})();
function setSuperclass(Child, Parent)
{
var F = function() { }
F.prototype = Parent.prototype
Child.prototype = new F()
Child.prototype.constructor = Child
Child.superclass = Parent.prototype
}
// Получить объект-прототип данному созданный на основе конструктора Constructor
this.__proto__.protoToConstructor = function(Constructor)
{
var object = this.__proto__;
while (object instanceof Object && object.constructor != Constructor) object = object.__proto__;
return (object instanceof Object && object.constructor == Constructor) ? object : null;
}
function extend(Child, Parent)
{
var F = function() { }
F.prototype = Parent.prototype
Child.prototype = new F()
Child.prototype.constructor = Child
Child.superclass = Parent.prototype
}
function DataPrototype()
{
this.toString = function() { return '[object ' + this.constructor.name + (this.toStringParam() != null ? (': ' + this.toStringParam()) : '') + ']'; }
this.toStringParam = function() { return null; }
}
setSuperclass(Obj1, DataPrototype);
function Obj1()
{
Obj1.superclass.constructor();
}
setSuperclass(Obj2, Obj1);
function Obj2()
{
Obj2.superclass.constructor();
}
setSuperclass(Obj3, Obj2);
function Obj3()
{
Obj3.superclass.constructor();
this.toStringParam = function() { return 'ыть-3'; }
}
setSuperclass(Obj4, Obj3);
function Obj4()
{
Obj4.superclass.constructor();
}
setSuperclass(Obj5, Obj4);
function Obj5()
{
Obj5.superclass.constructor();
this.toStringParam = function() { return 'ыть-5'; }
this.test = function() { print(this.protoToConstructor(Obj2)); }
}
print(new Obj1());
print(new Obj2());
print(new Obj3());
print(new Obj4());
print(new Obj5());
print('------------');
print((new Obj4()).protoToConstructor(Obj3));
(new Obj5()).test();