Ярлыки

.htaccess (4) тестирование (8) шаблоны проектирования (3) css (5) Debian (6) docker (2) Doctrine2 (6) Git (6) html (4) java (6) javascript (13) jquery (11) LFS (3) linux (23) mac os (4) mod_rewrite (2) MSSQL (4) MySQL (18) ORM Doctrine (17) patterns (3) PDO (3) perl (7) PHP (64) PHPUnit (8) Python (15) SEO (2) Silex (1) SimpleXML (1) SQL (14) ssh (4) Ubuntu (24) Yii1 (1) Zend Framework (19) ZendFramework2 (8)

суббота, 17 августа 2013 г.

Javascript. Один из вариантов наследования объектов.

function foo()
{
    this.name = "foo";
    this.testFoo = function () 
    {
        return "testFoo()";
    }
}

function bar()
{
    foo.call(this); // меняем контекст foo на bar
    this.getName = function () 
    {
        return this.name + "bar";
    }
    this.testBar = function ()
    {
        return "testBar()";
    }
    this.testFoo = this.testBar;
}

mybar = new bar();
alert(mybar.getName()); // foobar
alert(mybar.testFoo()); // testBar()

Комментариев нет:

Отправить комментарий