var inherit = function (Child, Parent) {
var F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
}
var inherit = function (Child, Parent) {
var F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
}
var inherit = function (Child, Parent) {
var F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
}
var inherit = function (Child, Parent) {
var F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
}
classical inheritance
1. Default Pattern
2. Rent-a-Constructor
3. Rent and Set Prototype
4. Share Prototype
5. Temp. Constructor
classical inheritance
1. Default Pattern
klass
2. Rent-a-Constructor
3. Rent and Set Prototype
4. Share Prototype
5. Temp. Constructor
var Parent = klass(
null,
{
__construct: function () {},
someMethod: function () {}
}
);
var Child = klass(
Parent,
{
__construct: function () {},
childMethod: function () {}
}
);
var Parent = klass(
null,
{
__construct: function () {},
someMethod: function () {}
}
);
var Child = klass(
Parent,
{
__construct: function () {},
childMethod: function () {}
}
);
var Parent = klass(
null,
{
__construct: function () {},
someMethod: function () {}
}
);
var Child = klass(
Parent,
{
__construct: function () {},
childMethod: function () {}
}
);
var Parent = klass(
null,
{
__construct: function () {},
someMethod: function () {}
}
);
var Child = klass(
Parent,
{
__construct: function () {},
childMethod: function () {}
}
);
var Parent = klass(
null,
{
__construct: function () {},
someMethod: function () {}
}
);
var Child = klass(
Parent,
{
__construct: function () {},
childMethod: function () {}
}
);
var Parent = klass(
null,
{
__construct: function () {},
someMethod: function () {}
}
);
var Child = klass(
Parent,
{
__construct: function () {},
childMethod: function () {}
}
);
var Parent = klass(
null,
{
__construct: function () {},
someMethod: function () {}
}
);
var Child = klass(
Parent,
{
__construct: function () {},
childMethod: function () {}
}
);
var Man = klass(
null,
{
__construct: function (what) {
console.log('man constructor');
this.name = what;
},
getName: function () {
return this.name;
}
}
);
var Man = klass(
null,
{
__construct: function (what) {
console.log('man constructor');
this.name = what;
},
getName: function () {
return this.name;
}
}
);
var Man = klass(
null,
{
__construct: function (what) {
console.log('man constructor');
this.name = what;
},
getName: function () {
return this.name;
}
}
);
var Man = klass(
null,
{
__construct: function (what) {
console.log('man constructor');
this.name = what;
},
getName: function () {
return this.name;
}
}
);
var Man = klass(
null,
{
__construct: function (what) {
console.log('man constructor');
this.name = what;
},
getName: function () {
return this.name;
}
}
);
var Man = klass(
null,
{
__construct: function (what) {
console.log('man constructor');
this.name = what;
},
getName: function () {
return this.name;
}
}
);
var Man = klass(
null,
{
__construct: function (what) {
console.log('man constructor');
this.name = what;
},
getName: function () {
return this.name;
}
}
);
var first = new Man('Adam');
// logs 'man constructor'
first.getName();
// 'Adam'
var first = new Man('Adam');
// logs 'man constructor'
first.getName();
// 'Adam'
var first = new Man('Adam');
// logs 'man constructor'
first.getName();
// 'Adam'
var first = new Man('Adam');
// logs 'man constructor'
first.getName();
// 'Adam'
var SuperMan = klass(
Man,
{
__construct: function (what) {
console.log('super man constructor');
},
getName: function () {
var name = SuperMan.uber.getName.call(this);
return 'I am ' + name;
}
}
);
var SuperMan = klass(
Man,
{
__construct: function (what) {
console.log('super man constructor');
},
getName: function () {
var name = SuperMan.uber.getName.call(this);
return 'I am ' + name;
}
}
);
var SuperMan = klass(
Man,
{
__construct: function (what) {
console.log('super man constructor');
},
getName: function () {
var name = SuperMan.uber.getName.call(this);
return 'I am ' + name;
}
}
);
var SuperMan = klass(
Man,
{
__construct: function (what) {
console.log('super man constructor');
},
getName: function () {
var name = SuperMan.uber.getName.call(this);
return 'I am ' + name;
}
}
);
var SuperMan = klass(
Man,
{
__construct: function (what) {
console.log('super man constructor');
},
getName: function () {
var name = SuperMan.uber.getName.call(this);
return 'I am ' + name;
}
}
);
var SuperMan = klass(
Man,
{
__construct: function (what) {
console.log('super man constructor');
},
getName: function () {
var name = SuperMan.uber.getName.call(this);
return 'I am ' + name;
}
}
);
var SuperMan = klass(
Man,
{
__construct: function (what) {
console.log('super man constructor');
},
getName: function () {
var name = SuperMan.uber.getName.call(this);
return 'I am ' + name;
}
}
);
var clark = new SuperMan('Clark Kent');
// logs 'man constructor'
// and 'super man constructor'
clark.getName();
// 'I am Clark Kent'
var clark = new SuperMan('Clark Kent');
// logs 'man constructor'
// and 'super man constructor'
clark.getName();
// 'I am Clark Kent'
var clark = new SuperMan('Clark Kent');
// logs 'man constructor'
// and 'super man constructor'
clark.getName();
// 'I am Clark Kent'
var clark = new SuperMan('Clark Kent');
// logs 'man constructor'
// and 'super man constructor'
clark.getName();
// 'I am Clark Kent'
var clark = new SuperMan('Clark Kent');
// logs 'man constructor'
// and 'super man constructor'
clark.getName();
// 'I am Clark Kent'
var klass = function (Parent, props) {
var Child, F, i;
Child = function () {
if (Child.uber && Child.uber.hasOwnProperty('__construct')) {
Child.uber.__construct.apply(this, arguments);
}
if (Child.prototype.hasOwnProperty('__construct')) {
Child.prototype.__construct.apply(this, arguments);
}
};
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = props[i];
}
}
return Child;
};
var klass = function (Parent, props) {
var Child, F, i;
Child = function () {
if (Child.uber && Child.uber.hasOwnProperty('__construct')) {
Child.uber.__construct.apply(this, arguments);
}
if (Child.prototype.hasOwnProperty('__construct')) {
Child.prototype.__construct.apply(this, arguments);
}
};
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = props[i];
}
}
return Child;
};
var klass = function (Parent, props) {
var Child, F, i;
Child = function () {
if (Child.uber && Child.uber.hasOwnProperty('__construct')) {
Child.uber.__construct.apply(this, arguments);
}
if (Child.prototype.hasOwnProperty('__construct')) {
Child.prototype.__construct.apply(this, arguments);
}
};
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = props[i];
}
}
return Child;
};
var klass = function (Parent, props) {
var Child, F, i;
Child = function () {
if (Child.uber && Child.uber.hasOwnProperty('__construct')) {
Child.uber.__construct.apply(this, arguments);
}
if (Child.prototype.hasOwnProperty('__construct')) {
Child.prototype.__construct.apply(this, arguments);
}
};
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = props[i];
}
}
return Child;
};
var klass = function (Parent, props) {
var Child, F, i;
Child = function () {
if (Child.uber && Child.uber.hasOwnProperty('__construct')) {
Child.uber.__construct.apply(this, arguments);
}
if (Child.prototype.hasOwnProperty('__construct')) {
Child.prototype.__construct.apply(this, arguments);
}
};
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = props[i];
}
}
return Child;
};
Child = function () {
if (Child.uber && Child.uber.hasOwnProperty('__construct')) {
Child.uber.__construct.apply(this, arguments);
}
if (Child.prototype.hasOwnProperty('__construct')) {
Child.prototype.__construct.apply(this, arguments);
}
};
Child = function () {
if (Child.uber && Child.uber.hasOwnProperty('__construct')) {
Child.uber.__construct.apply(this, arguments);
}
if (Child.prototype.hasOwnProperty('__construct')) {
Child.prototype.__construct.apply(this, arguments);
}
};
Child = function () {
if (Child.uber && Child.uber.hasOwnProperty('__construct')) {
Child.uber.__construct.apply(this, arguments);
}
if (Child.prototype.hasOwnProperty('__construct')) {
Child.prototype.__construct.apply(this, arguments);
}
};
Child = function () {
if (Child.uber && Child.uber.hasOwnProperty('__construct')) {
Child.uber.__construct.apply(this, arguments);
}
if (Child.prototype.hasOwnProperty('__construct')) {
Child.prototype.__construct.apply(this, arguments);
}
};
Child = function () {
if (Child.uber && Child.uber.hasOwnProperty('__construct')) {
Child.uber.__construct.apply(this, arguments);
}
if (Child.prototype.hasOwnProperty('__construct')) {
Child.prototype.__construct.apply(this, arguments);
}
};
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
var klass = function (Parent, props) {
/* ... */
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = props[i];
}
}
return Child;
};
var klass = function (Parent, props) {
/* ... */
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = props[i];
}
}
return Child;
};
var klass = function (Parent, props) {
/* ... */
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = props[i];
}
}
return Child;
};
var klass = function (Parent, props) {
/* ... */
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = props[i];
}
}
return Child;
};
var klass = function (Parent, props) {
/* ... */
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = props[i];
}
}
return Child;
};
var klass = function (Parent, props) {
/* ... */
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = props[i];
}
}
return Child;
};
var klass = function (Parent, props) {
var Child, F, i;
Child = function () {
if (Child.uber && Child.uber.hasOwnProperty('__construct')) {
Child.uber.__construct.apply(this, arguments);
}
if (Child.prototype.hasOwnProperty('__construct')) {
Child.prototype.__construct.apply(this, arguments);
}
};
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = props[i];
}
}
return Child;
};