SlideShare una empresa de Scribd logo
1 de 199
Descargar para leer sin conexión
{}
{}  1
'nelm.io'
  true
undefined
  null
{}
new Object();
{}
// v.s.
new Object();
(function (){
    var Object = function () {
        this.changed = true;
    }
    console.log(new Object());
}());

// {changed: true}
(function (){
    var Object = function () {
        this.changed = true;
    }
    console.log(new Object());
}());

// {changed: true}
(function (){
    var Object = function () {
        this.changed = true;
    }
    console.log(new Object());
}());

// {changed: true}
(function (){
    var Object = function () {
        this.changed = true;
    }
    console.log(new Object());
}());

// {changed: true}
(function (){
    var Object = function () {
        this.changed = true;
    }
    console.log(new Object());
}());

// {changed: true}
(function (){
    var Object = function () {
        this.changed = true;
    }
    console.log(new Object());
}());

// {changed: true}
{}
new Object();
var o = new Object(1);
console.log(o.constructor);

// function Number() { }
// new Number(1);
var o = new Object('1');
console.log(o.constructor);

// function String() { }
// new String('1');
var o = new Object(true);
console.log(o.constructor);

// function Boolean() { }
// new Boolean(true);
var a = {};
var b = new Object();
var c = Object();
var a = {};
var b = new Object();
var c = Object();
var a = {};
var b = new Object();
var c = Object();
new
new Object();
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar = new Car('Fiat');

// {brand: 'Fiat'}
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar = new Car('Fiat');

// {brand: 'Fiat'}
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar = new Car('Fiat');

// {brand: 'Fiat'}
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar = new Car('Fiat');

// {brand: 'Fiat'}
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar =        Car('Fiat');

// undefined
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar =        Car('Fiat');

// undefined
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar = new Car('Fiat');

// {brand: 'Fiat'}
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar = new Car('Fiat');

// {brand: 'Fiat'}
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
    console.log(
        this.constructor === Car
    );
    // true
};

myCar = new Car('Fiat');
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
    console.log(
        this.constructor === Car
    );
    // undefined
};

myCar =     Car('Fiat');
var Car, myCar;

Car = function (brand) {
    if (this.constructor !== Car) {
        return new Car(brand);
    }
    this.brand = brand;
};

myCar =     Car('Fiat');
var Car, myCar;

Car = function (brand) {
    if (this.constructor !== Car) {
        return new Car(brand);
    }
    this.brand = brand;
};

myCar = new Car('Fiat');
prototype
{}
prototype
var C = function () {};

console.log(C.prototype);

{
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};

console.log(C.prototype);

{
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};

console.log(C.prototype);

{
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};

console.log(C.prototype);

{
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};

console.log(C.prototype);

{
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};
C.prototype = {
   a: "A",
   b: "B",
   constructor: C
};

console.log(C.prototype);

{
    a: "A",
    b: "B",
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};
C.prototype = {
   a: "A",
   b: "B",
   constructor: C
};

console.log(C.prototype);

{
    a: "A",
    b: "B",
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};
C.prototype = {
   a: "A",
   b: "B",
   constructor: C // !!!
};

console.log(C.prototype);

{
    a: "A",
    b: "B",
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};
C.prototype = {
   a: "A",
   b: "B",
   constructor: C
};

console.log(C.prototype);

{
    a: "A",
    b: "B",
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};
C.prototype = {
   a: "A",
   b: "B",
   constructor: C
};

console.log(C.prototype);

{
    a: "A",
    b: "B",
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};
C.prototype = {
   a: "A",
   b: "B",
   constructor: C
};

console.log(C.prototype);

{
    a: "A",
    b: "B",
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};
C.prototype = {
   a: "A",
   b: "B",
   constructor: C
};

console.log(C.prototype);

{
    a: "A",
    b: "B",
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};



C.prototype.a = "A";
C.prototype.b = "B";



console.log(C.prototype);

{
    a: "A",
    b: "B",
    constructor: C,
    __proto__: Object.prototype
}
var C = function () {};



C.prototype.a = "A";
C.prototype.b = "B";



console.log(C.prototype);

{
    a: "A",
    b: "B",
    constructor: C,
    __proto__: Object.prototype
}
{}
prototype
property
  v.s.
attribute
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar = new Car('Fiat');

Car.prototype; // { /* ... */ }
myCar.prototype; // undefined
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar = new Car('Fiat');

Car.prototype; // { /* ... */ }
myCar.prototype; // undefined
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar = new Car('Fiat');

Car.prototype; // { /* ... */ }
myCar.prototype; // undefined
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar = new Car('Fiat');

Car.prototype; // { /* ... */ }
myCar.prototype; // undefined
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar = new Car('Fiat');

Car.prototype; // { /* ... */ }
myCar.prototype; // undefined
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

myCar = new Car('Fiat');

Car.prototype; // { /* ... */ }
myCar.prototype; // undefined
property
  v.s.
attribute
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

Car.prototype.getBrand = function () {
    return this.brand;
};

myCar = new Car('Fiat');
myCar.brand;
myCar.getBrand();
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

Car.prototype.getBrand = function () {
    return this.brand;
};

myCar = new Car('Fiat');
myCar.brand;
myCar.getBrand();
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

Car.prototype.getBrand = function () {
    return this.brand;
};

myCar = new Car('Fiat');
myCar.brand;
myCar.getBrand();
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

Car.prototype.getBrand = function () {
    return this.brand;
};

myCar = new Car('Fiat');
myCar.brand;
myCar.getBrand();
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

Car.prototype.getBrand = function () {
    return this.brand;
};

myCar = new Car('Fiat');
myCar.brand;
myCar.getBrand();
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

Car.prototype.getBrand = function () {
    return this.brand;
};

myCar = new Car('Fiat');
myCar.brand;
myCar.getBrand();
var Car, myCar;

Car = function (brand) {
    this.brand = brand;
};

Car.prototype.getBrand = function () {
    return this.brand;
};

myCar = new Car('Fiat');
myCar.brand;
myCar.getBrand();
{}
prototype
inheritance
classical
inheritance
  modern
classical
inheritance
var Car, ItalianCar, myCar;

Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {};

inherit(ItalianCar, Car);

myCar = new ItalianCar('Fiat');
var Car, ItalianCar, myCar;

Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {}

inherit(ItalianCar, Car);

myCar = new ItalianCar('Fiat');
var Car, ItalianCar, myCar;

Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {}

inherit(ItalianCar, Car);

myCar = new ItalianCar('Fiat');
var Car, ItalianCar, myCar;

Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {};

inherit(ItalianCar, Car);

myCar = new ItalianCar('Fiat');
var Car, ItalianCar, myCar;

Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {}

inherit(ItalianCar, Car);

myCar = new ItalianCar('Fiat');
var Car, ItalianCar, myCar;

Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {}

inherit(ItalianCar, Car);

myCar = new ItalianCar('Fiat');
var Car, ItalianCar, myCar;

Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {};

inherit(ItalianCar, Car);

myCar = new ItalianCar('Fiat');
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
2.   Rent-a-Constructor
3.   Rent and Set Prototype
4.   Share Prototype
5.   Temp. Constructor
var inherit = function (Child, Parent) {
  Child.prototype = new Parent();
}
var inherit = function (Child, Parent) {
  Child.prototype = new Parent();
}
myCar = new ItalianCar();

myCar.getBrand();
// 'Homemade'
var inherit = function (Child, Parent) {
  Child.prototype = new Parent();
}
myCar = new ItalianCar();

myCar.getBrand();
// 'Homemade'
var inherit = function (Child, Parent) {
  Child.prototype = new Parent();
}
myCar = new ItalianCar();

myCar.getBrand();
// 'Homemade'
var inherit = function (Child, Parent) {
  Child.prototype = new Parent();
}
myCar = new ItalianCar();

myCar.getBrand();
// 'Homemade'
myCar.brand = "Fiat";
myCar.getBrand(); // 'Fiat'
myCar.getBrand();
// 'Fiat'
myCar = new ItalianCar();
myCar.brand = 'Fiat';
myCar = new ItalianCar('Fiat')
myCar = new ItalianCar('Fiat')
myCar.getBrand(); // 'Homemade'
var Car, ItalianCar, myCar;

Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {}

inherit(ItalianCar, Car);
// ItalianCar.prototype = new Car();
classical inheritance
1.   Default Pattern
2.   Rent-a-Constructor
3.   Rent and Set Prototype
4.   Share Prototype
5.   Temp. Constructor
ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand; // 'undefined'
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand; // 'undefined'
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand; // 'undefined'
classical inheritance
1.   Default Pattern
2.   Rent-a-Constructor
3.   Rent and Set Prototype
4.   Share Prototype
5.   Temp. Constructor
ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();
ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();
ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();
ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand(); // 'Fiat'
delete myCar.brand;
myCar.getBrand(); // 'Homemade'
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand(); // 'Fiat'
delete myCar.brand;
myCar.getBrand(); // 'Homemade'
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand(); // 'Fiat'
delete myCar.brand;
myCar.getBrand(); // 'Homemade'
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand(); // 'Fiat'
delete myCar.brand;
myCar.getBrand(); // 'Homemade'
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand(); // 'Fiat'
delete myCar.brand;
myCar.getBrand(); // 'Homemade'
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand(); // 'Fiat'
delete myCar.brand;
myCar.getBrand(); // 'Homemade'
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand(); // 'Fiat'
delete myCar.brand;
myCar.getBrand(); // 'Homemade'
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand(); // 'Fiat'
delete myCar.brand;
myCar.getBrand(); // 'Homemade'
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}
ItalianCar.prototype = new Car();

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand(); // 'Fiat'
delete myCar.brand;
myCar.getBrand(); // 'Homemade'
var Car, ItalianCar, myCar;
Car = function (brand) {
  this.brand = brand || 'Homemade';
}
Car.prototype.getBrand = function () {
  return this.brand;
}

ItalianCar = function (brand) {
  Car.apply(this, [brand]);
}

myCar = new ItalianCar('Fiat');
myCar.brand; // 'Fiat';
myCar.getBrand; // 'undefined'
classical inheritance
1.   Default Pattern
2.   Rent-a-Constructor
3.   Rent and Set Prototype
4.   Share Prototype
5.   Temp. Constructor
var inherit = function (Child, Parent) {
  Child.prototype = Parent.prototype;
}
classical inheritance
1.   Default Pattern
2.   Rent-a-Constructor
3.   Rent and Set Prototype
4.   Share Prototype
5.   Temp. Constructor
var inherit = function (Child, Parent) {
  var F = function () {};
  F.prototype = Parent.prototype;
  Child.prototype = new F();
}
var inherit = function (Child, Parent) {
  var F = function () {};
  F.prototype = Parent.prototype;
  Child.prototype = new F();
}
var inherit = function (Child, Parent) {
  var F = function () {};
  F.prototype = Parent.prototype;
  Child.prototype = new F();
}
var inherit = function (Child, Parent) {
  var F = function () {};
  F.prototype = Parent.prototype;
  Child.prototype = new F();
}
var inherit = function (Child, Parent) {
  var F = function () {};
  F.prototype = Parent.prototype;
  Child.prototype = new F();
}
inherit(ItalianCar, Car);
myCar = new ItalianCar();
myCar.brand;    // undefined
myCar.getBrand; // function
inherit(ItalianCar, Car);
myCar = new ItalianCar();
myCar.brand;    // undefined
myCar.getBrand; // function
inherit(ItalianCar, Car);
myCar = new ItalianCar();
myCar.brand;    // undefined
myCar.getBrand; // function
inherit(ItalianCar, Car);
myCar = new ItalianCar();
myCar.brand;    // undefined
myCar.getBrand; // function
inherit(ItalianCar, Car);
myCar = new ItalianCar();
myCar.brand;    // undefined
myCar.getBrand; // function
inherit(ItalianCar, Car);
myCar = new ItalianCar();
myCar.brand;    // undefined
myCar.getBrand; // function
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;
};
X

Más contenido relacionado

La actualidad más candente

Journey of a C# developer into Javascript
Journey of a C# developer into JavascriptJourney of a C# developer into Javascript
Journey of a C# developer into JavascriptMassimo Franciosa
 
C++ for Java Developers (SwedenCpp Meetup 2017)
C++ for Java Developers (SwedenCpp Meetup 2017)C++ for Java Developers (SwedenCpp Meetup 2017)
C++ for Java Developers (SwedenCpp Meetup 2017)Patricia Aas
 
Mca 2nd sem u-4 operator overloading
Mca 2nd  sem u-4 operator overloadingMca 2nd  sem u-4 operator overloading
Mca 2nd sem u-4 operator overloadingRai University
 
LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: FunctionsAdam Crabtree
 
From Function1#apply to Kleisli
From Function1#apply to KleisliFrom Function1#apply to Kleisli
From Function1#apply to KleisliHermann Hueck
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++LPU
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract classAmit Trivedi
 
Computer notes - Reference Variables –II
Computer notes  - Reference Variables –IIComputer notes  - Reference Variables –II
Computer notes - Reference Variables –IIecomputernotes
 
Why should we use SIMPLE FACTORY pattern even when we have one class only?
Why should we use SIMPLE FACTORY pattern even when we have one class only?Why should we use SIMPLE FACTORY pattern even when we have one class only?
Why should we use SIMPLE FACTORY pattern even when we have one class only?Rafal Ksiazek
 
Monoids, Store, and Dependency Injection - Abstractions for Spark Streaming Jobs
Monoids, Store, and Dependency Injection - Abstractions for Spark Streaming JobsMonoids, Store, and Dependency Injection - Abstractions for Spark Streaming Jobs
Monoids, Store, and Dependency Injection - Abstractions for Spark Streaming JobsRyan Weald
 
the-lost-art-of-plpgsql
the-lost-art-of-plpgsqlthe-lost-art-of-plpgsql
the-lost-art-of-plpgsqlRobert Treat
 
computer notes - Data Structures - 18
computer notes - Data Structures - 18computer notes - Data Structures - 18
computer notes - Data Structures - 18ecomputernotes
 
Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)Hermann Hueck
 
Use Applicative where applicable!
Use Applicative where applicable!Use Applicative where applicable!
Use Applicative where applicable!Hermann Hueck
 

La actualidad más candente (20)

C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
C++ functions
C++ functionsC++ functions
C++ functions
 
F[5]
F[5]F[5]
F[5]
 
Journey of a C# developer into Javascript
Journey of a C# developer into JavascriptJourney of a C# developer into Javascript
Journey of a C# developer into Javascript
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
C++ for Java Developers (SwedenCpp Meetup 2017)
C++ for Java Developers (SwedenCpp Meetup 2017)C++ for Java Developers (SwedenCpp Meetup 2017)
C++ for Java Developers (SwedenCpp Meetup 2017)
 
Mca 2nd sem u-4 operator overloading
Mca 2nd  sem u-4 operator overloadingMca 2nd  sem u-4 operator overloading
Mca 2nd sem u-4 operator overloading
 
Function (rule in programming)
Function (rule in programming)Function (rule in programming)
Function (rule in programming)
 
LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
 
From Function1#apply to Kleisli
From Function1#apply to KleisliFrom Function1#apply to Kleisli
From Function1#apply to Kleisli
 
Time for Functions
Time for FunctionsTime for Functions
Time for Functions
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract class
 
Computer notes - Reference Variables –II
Computer notes  - Reference Variables –IIComputer notes  - Reference Variables –II
Computer notes - Reference Variables –II
 
Why should we use SIMPLE FACTORY pattern even when we have one class only?
Why should we use SIMPLE FACTORY pattern even when we have one class only?Why should we use SIMPLE FACTORY pattern even when we have one class only?
Why should we use SIMPLE FACTORY pattern even when we have one class only?
 
Monoids, Store, and Dependency Injection - Abstractions for Spark Streaming Jobs
Monoids, Store, and Dependency Injection - Abstractions for Spark Streaming JobsMonoids, Store, and Dependency Injection - Abstractions for Spark Streaming Jobs
Monoids, Store, and Dependency Injection - Abstractions for Spark Streaming Jobs
 
the-lost-art-of-plpgsql
the-lost-art-of-plpgsqlthe-lost-art-of-plpgsql
the-lost-art-of-plpgsql
 
computer notes - Data Structures - 18
computer notes - Data Structures - 18computer notes - Data Structures - 18
computer notes - Data Structures - 18
 
Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)
 
Use Applicative where applicable!
Use Applicative where applicable!Use Applicative where applicable!
Use Applicative where applicable!
 

Similar a Oop in java script

#include iostream #include string#includeiomanip using.docx
#include iostream #include string#includeiomanip using.docx#include iostream #include string#includeiomanip using.docx
#include iostream #include string#includeiomanip using.docxajoy21
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript FunctionsColin DeCarlo
 
For the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfFor the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfarjunhassan8
 
Classes and Objects In C# With Example
Classes and Objects In C# With ExampleClasses and Objects In C# With Example
Classes and Objects In C# With ExampleCheezy Code
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web ModuleMorgan Cheng
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftOleksandr Stepanov
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascriptAbimbola Idowu
 
#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docxmayank272369
 
Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfsooryasalini
 
I need to do the followingAdd a new item to the inventory m.pdf
I need to do the followingAdd a new item to the inventory m.pdfI need to do the followingAdd a new item to the inventory m.pdf
I need to do the followingAdd a new item to the inventory m.pdfadianantsolutions
 
Javascript 基础
Javascript 基础Javascript 基础
Javascript 基础Alipay
 
#include iostream #include string #include fstream std.docx
#include iostream #include string #include fstream  std.docx#include iostream #include string #include fstream  std.docx
#include iostream #include string #include fstream std.docxajoy21
 
Clean code in JavaScript
Clean code in JavaScriptClean code in JavaScript
Clean code in JavaScriptMathieu Breton
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 ReviewSperasoft
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 

Similar a Oop in java script (20)

#include iostream #include string#includeiomanip using.docx
#include iostream #include string#includeiomanip using.docx#include iostream #include string#includeiomanip using.docx
#include iostream #include string#includeiomanip using.docx
 
JavaScript Core
JavaScript CoreJavaScript Core
JavaScript Core
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
For the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfFor the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdf
 
Classes and Objects In C# With Example
Classes and Objects In C# With ExampleClasses and Objects In C# With Example
Classes and Objects In C# With Example
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
 
Java Script Best Practices
Java Script Best PracticesJava Script Best Practices
Java Script Best Practices
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascript
 
Testing AngularJS
Testing AngularJSTesting AngularJS
Testing AngularJS
 
#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx
 
Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdf
 
I need to do the followingAdd a new item to the inventory m.pdf
I need to do the followingAdd a new item to the inventory m.pdfI need to do the followingAdd a new item to the inventory m.pdf
I need to do the followingAdd a new item to the inventory m.pdf
 
Javascript 基础
Javascript 基础Javascript 基础
Javascript 基础
 
app.js.docx
app.js.docxapp.js.docx
app.js.docx
 
#include iostream #include string #include fstream std.docx
#include iostream #include string #include fstream  std.docx#include iostream #include string #include fstream  std.docx
#include iostream #include string #include fstream std.docx
 
Clean code in JavaScript
Clean code in JavaScriptClean code in JavaScript
Clean code in JavaScript
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 Review
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 

Más de Pierre Spring

Responsive Web at Webtuesday
Responsive Web at WebtuesdayResponsive Web at Webtuesday
Responsive Web at WebtuesdayPierre Spring
 
Frontend Performance - Web Entwickler Forum
Frontend Performance - Web Entwickler ForumFrontend Performance - Web Entwickler Forum
Frontend Performance - Web Entwickler ForumPierre Spring
 
JSDay Italy - Backbone.js
JSDay Italy - Backbone.jsJSDay Italy - Backbone.js
JSDay Italy - Backbone.jsPierre Spring
 
JSGeneve - Backbone.js
JSGeneve - Backbone.jsJSGeneve - Backbone.js
JSGeneve - Backbone.jsPierre Spring
 
Introduction to Scrum
Introduction to ScrumIntroduction to Scrum
Introduction to ScrumPierre Spring
 
Varnish Lightning Talk
Varnish Lightning TalkVarnish Lightning Talk
Varnish Lightning TalkPierre Spring
 
Speedy App: Frontend Performance Considerations
Speedy App: Frontend Performance ConsiderationsSpeedy App: Frontend Performance Considerations
Speedy App: Frontend Performance ConsiderationsPierre Spring
 

Más de Pierre Spring (7)

Responsive Web at Webtuesday
Responsive Web at WebtuesdayResponsive Web at Webtuesday
Responsive Web at Webtuesday
 
Frontend Performance - Web Entwickler Forum
Frontend Performance - Web Entwickler ForumFrontend Performance - Web Entwickler Forum
Frontend Performance - Web Entwickler Forum
 
JSDay Italy - Backbone.js
JSDay Italy - Backbone.jsJSDay Italy - Backbone.js
JSDay Italy - Backbone.js
 
JSGeneve - Backbone.js
JSGeneve - Backbone.jsJSGeneve - Backbone.js
JSGeneve - Backbone.js
 
Introduction to Scrum
Introduction to ScrumIntroduction to Scrum
Introduction to Scrum
 
Varnish Lightning Talk
Varnish Lightning TalkVarnish Lightning Talk
Varnish Lightning Talk
 
Speedy App: Frontend Performance Considerations
Speedy App: Frontend Performance ConsiderationsSpeedy App: Frontend Performance Considerations
Speedy App: Frontend Performance Considerations
 

Último

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 

Último (20)

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 

Oop in java script

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. {}
  • 8. {} 1 'nelm.io' true undefined null
  • 9. {}
  • 12. (function (){ var Object = function () { this.changed = true; } console.log(new Object()); }()); // {changed: true}
  • 13. (function (){ var Object = function () { this.changed = true; } console.log(new Object()); }()); // {changed: true}
  • 14. (function (){ var Object = function () { this.changed = true; } console.log(new Object()); }()); // {changed: true}
  • 15. (function (){ var Object = function () { this.changed = true; } console.log(new Object()); }()); // {changed: true}
  • 16. (function (){ var Object = function () { this.changed = true; } console.log(new Object()); }()); // {changed: true}
  • 17. (function (){ var Object = function () { this.changed = true; } console.log(new Object()); }()); // {changed: true}
  • 19. var o = new Object(1); console.log(o.constructor); // function Number() { } // new Number(1);
  • 20. var o = new Object('1'); console.log(o.constructor); // function String() { } // new String('1');
  • 21. var o = new Object(true); console.log(o.constructor); // function Boolean() { } // new Boolean(true);
  • 22. var a = {}; var b = new Object(); var c = Object();
  • 23. var a = {}; var b = new Object(); var c = Object();
  • 24. var a = {}; var b = new Object(); var c = Object();
  • 25. new
  • 27. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = new Car('Fiat'); // {brand: 'Fiat'}
  • 28. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = new Car('Fiat'); // {brand: 'Fiat'}
  • 29. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = new Car('Fiat'); // {brand: 'Fiat'}
  • 30. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = new Car('Fiat'); // {brand: 'Fiat'}
  • 31. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = Car('Fiat'); // undefined
  • 32. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = Car('Fiat'); // undefined
  • 33. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = new Car('Fiat'); // {brand: 'Fiat'}
  • 34. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = new Car('Fiat'); // {brand: 'Fiat'}
  • 35. var Car, myCar; Car = function (brand) { this.brand = brand; console.log( this.constructor === Car ); // true }; myCar = new Car('Fiat');
  • 36. var Car, myCar; Car = function (brand) { this.brand = brand; console.log( this.constructor === Car ); // undefined }; myCar = Car('Fiat');
  • 37. var Car, myCar; Car = function (brand) { if (this.constructor !== Car) { return new Car(brand); } this.brand = brand; }; myCar = Car('Fiat');
  • 38. var Car, myCar; Car = function (brand) { if (this.constructor !== Car) { return new Car(brand); } this.brand = brand; }; myCar = new Car('Fiat');
  • 41. var C = function () {}; console.log(C.prototype); { constructor: C, __proto__: Object.prototype }
  • 42. var C = function () {}; console.log(C.prototype); { constructor: C, __proto__: Object.prototype }
  • 43. var C = function () {}; console.log(C.prototype); { constructor: C, __proto__: Object.prototype }
  • 44. var C = function () {}; console.log(C.prototype); { constructor: C, __proto__: Object.prototype }
  • 45. var C = function () {}; console.log(C.prototype); { constructor: C, __proto__: Object.prototype }
  • 46. var C = function () {}; C.prototype = { a: "A", b: "B", constructor: C }; console.log(C.prototype); { a: "A", b: "B", constructor: C, __proto__: Object.prototype }
  • 47. var C = function () {}; C.prototype = { a: "A", b: "B", constructor: C }; console.log(C.prototype); { a: "A", b: "B", constructor: C, __proto__: Object.prototype }
  • 48. var C = function () {}; C.prototype = { a: "A", b: "B", constructor: C // !!! }; console.log(C.prototype); { a: "A", b: "B", constructor: C, __proto__: Object.prototype }
  • 49. var C = function () {}; C.prototype = { a: "A", b: "B", constructor: C }; console.log(C.prototype); { a: "A", b: "B", constructor: C, __proto__: Object.prototype }
  • 50. var C = function () {}; C.prototype = { a: "A", b: "B", constructor: C }; console.log(C.prototype); { a: "A", b: "B", constructor: C, __proto__: Object.prototype }
  • 51. var C = function () {}; C.prototype = { a: "A", b: "B", constructor: C }; console.log(C.prototype); { a: "A", b: "B", constructor: C, __proto__: Object.prototype }
  • 52. var C = function () {}; C.prototype = { a: "A", b: "B", constructor: C }; console.log(C.prototype); { a: "A", b: "B", constructor: C, __proto__: Object.prototype }
  • 53. var C = function () {}; C.prototype.a = "A"; C.prototype.b = "B"; console.log(C.prototype); { a: "A", b: "B", constructor: C, __proto__: Object.prototype }
  • 54. var C = function () {}; C.prototype.a = "A"; C.prototype.b = "B"; console.log(C.prototype); { a: "A", b: "B", constructor: C, __proto__: Object.prototype }
  • 57. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = new Car('Fiat'); Car.prototype; // { /* ... */ } myCar.prototype; // undefined
  • 58. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = new Car('Fiat'); Car.prototype; // { /* ... */ } myCar.prototype; // undefined
  • 59. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = new Car('Fiat'); Car.prototype; // { /* ... */ } myCar.prototype; // undefined
  • 60. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = new Car('Fiat'); Car.prototype; // { /* ... */ } myCar.prototype; // undefined
  • 61. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = new Car('Fiat'); Car.prototype; // { /* ... */ } myCar.prototype; // undefined
  • 62. var Car, myCar; Car = function (brand) { this.brand = brand; }; myCar = new Car('Fiat'); Car.prototype; // { /* ... */ } myCar.prototype; // undefined
  • 64. var Car, myCar; Car = function (brand) { this.brand = brand; }; Car.prototype.getBrand = function () { return this.brand; }; myCar = new Car('Fiat'); myCar.brand; myCar.getBrand();
  • 65. var Car, myCar; Car = function (brand) { this.brand = brand; }; Car.prototype.getBrand = function () { return this.brand; }; myCar = new Car('Fiat'); myCar.brand; myCar.getBrand();
  • 66. var Car, myCar; Car = function (brand) { this.brand = brand; }; Car.prototype.getBrand = function () { return this.brand; }; myCar = new Car('Fiat'); myCar.brand; myCar.getBrand();
  • 67. var Car, myCar; Car = function (brand) { this.brand = brand; }; Car.prototype.getBrand = function () { return this.brand; }; myCar = new Car('Fiat'); myCar.brand; myCar.getBrand();
  • 68. var Car, myCar; Car = function (brand) { this.brand = brand; }; Car.prototype.getBrand = function () { return this.brand; }; myCar = new Car('Fiat'); myCar.brand; myCar.getBrand();
  • 69. var Car, myCar; Car = function (brand) { this.brand = brand; }; Car.prototype.getBrand = function () { return this.brand; }; myCar = new Car('Fiat'); myCar.brand; myCar.getBrand();
  • 70.
  • 71.
  • 72. var Car, myCar; Car = function (brand) { this.brand = brand; }; Car.prototype.getBrand = function () { return this.brand; }; myCar = new Car('Fiat'); myCar.brand; myCar.getBrand();
  • 77. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) {}; inherit(ItalianCar, Car); myCar = new ItalianCar('Fiat');
  • 78. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) {} inherit(ItalianCar, Car); myCar = new ItalianCar('Fiat');
  • 79. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) {} inherit(ItalianCar, Car); myCar = new ItalianCar('Fiat');
  • 80. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) {}; inherit(ItalianCar, Car); myCar = new ItalianCar('Fiat');
  • 81. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) {} inherit(ItalianCar, Car); myCar = new ItalianCar('Fiat');
  • 82. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) {} inherit(ItalianCar, Car); myCar = new ItalianCar('Fiat');
  • 83. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) {}; inherit(ItalianCar, Car); myCar = new ItalianCar('Fiat');
  • 84. classical inheritance 1. Default Pattern 2. Rent-a-Constructor 3. Rent and Set Prototype 4. Share Prototype 5. Temp. Constructor
  • 85. classical inheritance 1. Default Pattern 2. Rent-a-Constructor 3. Rent and Set Prototype 4. Share Prototype 5. Temp. Constructor
  • 86. var inherit = function (Child, Parent) { Child.prototype = new Parent(); }
  • 87. var inherit = function (Child, Parent) { Child.prototype = new Parent(); } myCar = new ItalianCar(); myCar.getBrand(); // 'Homemade'
  • 88. var inherit = function (Child, Parent) { Child.prototype = new Parent(); } myCar = new ItalianCar(); myCar.getBrand(); // 'Homemade'
  • 89. var inherit = function (Child, Parent) { Child.prototype = new Parent(); } myCar = new ItalianCar(); myCar.getBrand(); // 'Homemade'
  • 90. var inherit = function (Child, Parent) { Child.prototype = new Parent(); } myCar = new ItalianCar(); myCar.getBrand(); // 'Homemade'
  • 93. myCar = new ItalianCar(); myCar.brand = 'Fiat';
  • 94. myCar = new ItalianCar('Fiat')
  • 95. myCar = new ItalianCar('Fiat') myCar.getBrand(); // 'Homemade'
  • 96. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) {} inherit(ItalianCar, Car); // ItalianCar.prototype = new Car();
  • 97. classical inheritance 1. Default Pattern 2. Rent-a-Constructor 3. Rent and Set Prototype 4. Share Prototype 5. Temp. Constructor
  • 98. ItalianCar = function (brand) { Car.apply(this, [brand]); }
  • 99. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat';
  • 100. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat';
  • 101. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat';
  • 102. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat';
  • 103. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat';
  • 104. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand; // 'undefined'
  • 105. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand; // 'undefined'
  • 106. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand; // 'undefined'
  • 107.
  • 108. classical inheritance 1. Default Pattern 2. Rent-a-Constructor 3. Rent and Set Prototype 4. Share Prototype 5. Temp. Constructor
  • 109. ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car();
  • 110. ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car();
  • 111. ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car();
  • 112. ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car();
  • 113. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car(); myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand(); // 'Fiat' delete myCar.brand; myCar.getBrand(); // 'Homemade'
  • 114. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car(); myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand(); // 'Fiat' delete myCar.brand; myCar.getBrand(); // 'Homemade'
  • 115. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car(); myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand(); // 'Fiat' delete myCar.brand; myCar.getBrand(); // 'Homemade'
  • 116. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car(); myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand(); // 'Fiat' delete myCar.brand; myCar.getBrand(); // 'Homemade'
  • 117. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car(); myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand(); // 'Fiat' delete myCar.brand; myCar.getBrand(); // 'Homemade'
  • 118. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car(); myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand(); // 'Fiat' delete myCar.brand; myCar.getBrand(); // 'Homemade'
  • 119. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car(); myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand(); // 'Fiat' delete myCar.brand; myCar.getBrand(); // 'Homemade'
  • 120. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car(); myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand(); // 'Fiat' delete myCar.brand; myCar.getBrand(); // 'Homemade'
  • 121. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } ItalianCar.prototype = new Car(); myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand(); // 'Fiat' delete myCar.brand; myCar.getBrand(); // 'Homemade'
  • 122. var Car, ItalianCar, myCar; Car = function (brand) { this.brand = brand || 'Homemade'; } Car.prototype.getBrand = function () { return this.brand; } ItalianCar = function (brand) { Car.apply(this, [brand]); } myCar = new ItalianCar('Fiat'); myCar.brand; // 'Fiat'; myCar.getBrand; // 'undefined'
  • 123.
  • 124. classical inheritance 1. Default Pattern 2. Rent-a-Constructor 3. Rent and Set Prototype 4. Share Prototype 5. Temp. Constructor
  • 125. var inherit = function (Child, Parent) { Child.prototype = Parent.prototype; }
  • 126.
  • 127. classical inheritance 1. Default Pattern 2. Rent-a-Constructor 3. Rent and Set Prototype 4. Share Prototype 5. Temp. Constructor
  • 128. var inherit = function (Child, Parent) { var F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); }
  • 129. var inherit = function (Child, Parent) { var F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); }
  • 130. var inherit = function (Child, Parent) { var F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); }
  • 131. var inherit = function (Child, Parent) { var F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); }
  • 132. var inherit = function (Child, Parent) { var F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); }
  • 133.
  • 134. inherit(ItalianCar, Car); myCar = new ItalianCar(); myCar.brand; // undefined myCar.getBrand; // function
  • 135. inherit(ItalianCar, Car); myCar = new ItalianCar(); myCar.brand; // undefined myCar.getBrand; // function
  • 136. inherit(ItalianCar, Car); myCar = new ItalianCar(); myCar.brand; // undefined myCar.getBrand; // function
  • 137. inherit(ItalianCar, Car); myCar = new ItalianCar(); myCar.brand; // undefined myCar.getBrand; // function
  • 138. inherit(ItalianCar, Car); myCar = new ItalianCar(); myCar.brand; // undefined myCar.getBrand; // function
  • 139. inherit(ItalianCar, Car); myCar = new ItalianCar(); myCar.brand; // undefined myCar.getBrand; // function
  • 140. var inherit = function (Child, Parent) { var F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.uber = Parent.prototype; }
  • 141. var inherit = function (Child, Parent) { var F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.uber = Parent.prototype; }
  • 142. var inherit = function (Child, Parent) { var F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.uber = Parent.prototype; Child.prototype.constructor = Child; }
  • 143. var inherit = function (Child, Parent) { var F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.uber = Parent.prototype; Child.prototype.constructor = Child; }
  • 144. classical inheritance 1. Default Pattern 2. Rent-a-Constructor 3. Rent and Set Prototype 4. Share Prototype 5. Temp. Constructor
  • 145. classical inheritance 1. Default Pattern klass 2. Rent-a-Constructor 3. Rent and Set Prototype 4. Share Prototype 5. Temp. Constructor
  • 146. var Parent = klass( null, { __construct: function () {}, someMethod: function () {} } ); var Child = klass( Parent, { __construct: function () {}, childMethod: function () {} } );
  • 147. var Parent = klass( null, { __construct: function () {}, someMethod: function () {} } ); var Child = klass( Parent, { __construct: function () {}, childMethod: function () {} } );
  • 148. var Parent = klass( null, { __construct: function () {}, someMethod: function () {} } ); var Child = klass( Parent, { __construct: function () {}, childMethod: function () {} } );
  • 149. var Parent = klass( null, { __construct: function () {}, someMethod: function () {} } ); var Child = klass( Parent, { __construct: function () {}, childMethod: function () {} } );
  • 150. var Parent = klass( null, { __construct: function () {}, someMethod: function () {} } ); var Child = klass( Parent, { __construct: function () {}, childMethod: function () {} } );
  • 151. var Parent = klass( null, { __construct: function () {}, someMethod: function () {} } ); var Child = klass( Parent, { __construct: function () {}, childMethod: function () {} } );
  • 152. var Parent = klass( null, { __construct: function () {}, someMethod: function () {} } ); var Child = klass( Parent, { __construct: function () {}, childMethod: function () {} } );
  • 153. var Man = klass( null, { __construct: function (what) { console.log('man constructor'); this.name = what; }, getName: function () { return this.name; } } );
  • 154. var Man = klass( null, { __construct: function (what) { console.log('man constructor'); this.name = what; }, getName: function () { return this.name; } } );
  • 155. var Man = klass( null, { __construct: function (what) { console.log('man constructor'); this.name = what; }, getName: function () { return this.name; } } );
  • 156. var Man = klass( null, { __construct: function (what) { console.log('man constructor'); this.name = what; }, getName: function () { return this.name; } } );
  • 157. var Man = klass( null, { __construct: function (what) { console.log('man constructor'); this.name = what; }, getName: function () { return this.name; } } );
  • 158. var Man = klass( null, { __construct: function (what) { console.log('man constructor'); this.name = what; }, getName: function () { return this.name; } } );
  • 159. var Man = klass( null, { __construct: function (what) { console.log('man constructor'); this.name = what; }, getName: function () { return this.name; } } );
  • 160. var first = new Man('Adam'); // logs 'man constructor' first.getName(); // 'Adam'
  • 161. var first = new Man('Adam'); // logs 'man constructor' first.getName(); // 'Adam'
  • 162. var first = new Man('Adam'); // logs 'man constructor' first.getName(); // 'Adam'
  • 163. var first = new Man('Adam'); // logs 'man constructor' first.getName(); // 'Adam'
  • 164. 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; } } );
  • 165. 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; } } );
  • 166. 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; } } );
  • 167. 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; } } );
  • 168. 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; } } );
  • 169. 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; } } );
  • 170. 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; } } );
  • 171. var clark = new SuperMan('Clark Kent'); // logs 'man constructor' // and 'super man constructor' clark.getName(); // 'I am Clark Kent'
  • 172. var clark = new SuperMan('Clark Kent'); // logs 'man constructor' // and 'super man constructor' clark.getName(); // 'I am Clark Kent'
  • 173. var clark = new SuperMan('Clark Kent'); // logs 'man constructor' // and 'super man constructor' clark.getName(); // 'I am Clark Kent'
  • 174. var clark = new SuperMan('Clark Kent'); // logs 'man constructor' // and 'super man constructor' clark.getName(); // 'I am Clark Kent'
  • 175. var clark = new SuperMan('Clark Kent'); // logs 'man constructor' // and 'super man constructor' clark.getName(); // 'I am Clark Kent'
  • 176. 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; };
  • 177. 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; };
  • 178. 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; };
  • 179. 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; };
  • 180. 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; };
  • 181. 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); } };
  • 182. 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); } };
  • 183. 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); } };
  • 184. 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); } };
  • 185. 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); } };
  • 186. Parent = Parent || Object; F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.uber = Parent.prototype; Child.prototype.constructor = Child;
  • 187. Parent = Parent || Object; F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.uber = Parent.prototype; Child.prototype.constructor = Child;
  • 188. Parent = Parent || Object; F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.uber = Parent.prototype; Child.prototype.constructor = Child;
  • 189. Parent = Parent || Object; F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.uber = Parent.prototype; Child.prototype.constructor = Child;
  • 190. Parent = Parent || Object; F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.uber = Parent.prototype; Child.prototype.constructor = Child;
  • 191. Parent = Parent || Object; F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.uber = Parent.prototype; Child.prototype.constructor = Child;
  • 192. var klass = function (Parent, props) { /* ... */ for (i in props) { if (props.hasOwnProperty(i)) { Child.prototype[i] = props[i]; } } return Child; };
  • 193. var klass = function (Parent, props) { /* ... */ for (i in props) { if (props.hasOwnProperty(i)) { Child.prototype[i] = props[i]; } } return Child; };
  • 194. var klass = function (Parent, props) { /* ... */ for (i in props) { if (props.hasOwnProperty(i)) { Child.prototype[i] = props[i]; } } return Child; };
  • 195. var klass = function (Parent, props) { /* ... */ for (i in props) { if (props.hasOwnProperty(i)) { Child.prototype[i] = props[i]; } } return Child; };
  • 196. var klass = function (Parent, props) { /* ... */ for (i in props) { if (props.hasOwnProperty(i)) { Child.prototype[i] = props[i]; } } return Child; };
  • 197. var klass = function (Parent, props) { /* ... */ for (i in props) { if (props.hasOwnProperty(i)) { Child.prototype[i] = props[i]; } } return Child; };
  • 198. 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; };
  • 199. X