*****
function identify() {
    return this.name.toUpperCase();
}

function speak() {
    var greeting = "Witaj, jestem " + identify.call( this );
    console.log( greeting );
}

var me = {
    name: "Kyle"
};

var you = {
    name: "Czytelnik"
};

identify.call( me ); // KYLE.
identify.call( you ); // CZYTELNIK.

speak.call( me ); // Witaj, jestem KYLE.
speak.call( you ); // Witaj, jestem CZYTELNIK.
*****
function identify(context) {
    return context.name.toUpperCase();
}

function speak(context) {
    var greeting = "Witaj, jestem " + identify( context );
    console.log( greeting );
}

identify( you ); // CZYTELNIK.
speak( me ); // Witaj, jestem KYLE.
*****

function foo(num) {
    console.log( "foo: " + num );

    // Prba okrelenia liczby wywoa funkcji foo().
    this.count++;
}

foo.count = 0;

var i;

for (i=0; i<10; i++) {
    if (i > 5) {
        foo( i );
    }
}
// foo: 6
// foo: 7
// foo: 8
// foo: 9

// Ile razy zostaa wywoana funkcja foo()?
console.log( foo.count ); // 0 - Co u licha?
*****
function foo(num) {
    console.log( "foo: " + num );

    // Prba okrelenia liczby wywoa funkcji foo().
    data.count++;
}

var data = {
    count: 0
};

var i;

for (i=0; i<10; i++) {
    if (i > 5) {
        foo( i );
    }
}
// foo: 6
// foo: 7
// foo: 8
// foo: 9

// Ile razy zostaa wywoana funkcja foo()?
console.log( data.count ); // 4
*****
function foo() {
    foo.count = 4; // Tutaj 'foo' odwouje si do tej funkcji.
}

setTimeout( function(){
    // Funkcja anonimowa (pozbawiona nazwy)
    // nie moe si odwoywa do samej siebie.
}, 10 );

*****
function foo(num) {
    console.log( "foo: " + num );

    // Prba okrelenia liczby wywoa funkcji foo().
    foo.count++;
}

foo.count = 0;

var i;

for (i=0; i<10; i++) {
    if (i > 5) {
        foo( i );
    }
}
// foo: 6
// foo: 7
// foo: 8
// foo: 9

// Ile razy zostaa wywoana funkcja foo()?
console.log( foo.count ); // 4
*****
function foo(num) {
    console.log( "foo: " + num );

    // Prba okrelenia liczby wywoa funkcji foo().
    // Uwaga: 'this' to teraz naprawd JEST 'foo', 
    // co wynika ze sposobu wywoania 'foo' (patrz opis poniej).
    this.count++;
}

foo.count = 0;

var i;

for (i=0; i<10; i++) {
    if (i > 5) {
        // Uywajc 'call(..)', mamy pewno, e 'this'
        // odwouje si do obiektu funkcji ('foo').
        foo.call( foo, i );
    }
}
// foo: 6
// foo: 7
// foo: 8
// foo: 9

// Ile razy zostaa wywoana funkcja foo()?
console.log( foo.count ); // 4
*****
function foo() {
    var a = 2;
    this.bar();
}

function bar() {
    console.log( this.a );
}

foo(); //ReferenceError: niezdefiniowane.
*****

??





14	(	Rozdzia 1. Bd! W dokumencie nie ma tekstu o podanym stylu.

			Bd! W dokumencie nie ma tekstu o podanym stylu.	(	15



					13

