Kullanıcı: freeman
freeman
01.03.2020 19:03 ~ 01.03.2020 19:10
Call metodu, her fonksiyonun static alan adı verilen alanında bulunur ve görevi verilen parametreler ve bağlamda o metodu çalıştırmaktır.

Bir fonksiyon tanımlayalım;
var foo = function() { console.log( this ); }

Fonksiyonu normal yoldan çalıştıralım;
foo();
Burada fonksiyon global alanda çağırıldığı için "window" nesnesi bağlamında çalışır. Dolayısıyla konsola window nesnesi dökümlenir.

Fonksiyonu call metodu yardımıyla çalıştıralım;
foo.call( { bar: "baz" });
Bu yöntemde ise metot verilen özel bir nesneyi bağlam (*: context) olarak aldı. Dolayısıyla konsola aldığı nesne dökümlenir.

Call metodu ilk parametrede fonksiyonun this sözcüğüne atanacak bağlam nesnesini kabul eder. Ondan sonra gelecek bütün parametreler sırayla fonksiyonun parametre tüneline enjekte edilir. Yani ilk parametre this sabitine, diğerleri argüman tüneline gönderilir.

Function.call( context, arg1, arg2, ... );

Dikkat ettiyseniz çalıştıracağınız fonksiyona parametreleri manuel olarak tek tek yazmamız gerekir. Eğer çalıştıracağımız fonksiyonun kabul ettiği parametreler elimizdeyse, bunlara ne göndereceğimizi biliyorsak call metodu işimizi görecektir.

Ancak her zaman parametreler elimizde tam olarak bulunmayabilir. Dahası çalıştıracağımız fonksiyon çok biçimli (*: polymorphic) davranan bir metot da olabilir. Bu durumlarda call metodu yetersiz kalacaktır.

Onun için de;

bkz
javascript apply metodu
bkz
javascript bind metodu
#programlama #javascript

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /var/www/html/application/1.1.0/core/MY_Controller.php:95)

Filename: cookie/cookie.php

Line Number: 61

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /var/www/html/application/1.1.0/core/MY_Controller.php:95)

Filename: cookie/cookie.php

Line Number: 61

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /var/www/html/application/1.1.0/core/MY_Controller.php:95)

Filename: cookie/cookie.php

Line Number: 61

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /var/www/html/application/1.1.0/core/MY_Controller.php:95)

Filename: cookie/cookie.php

Line Number: 61

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /var/www/html/application/1.1.0/core/MY_Controller.php:95)

Filename: cookie/cookie.php

Line Number: 61

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /var/www/html/application/1.1.0/core/MY_Controller.php:95)

Filename: cookie/cookie.php

Line Number: 61

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /var/www/html/application/1.1.0/core/MY_Controller.php:95)

Filename: cookie/cookie.php

Line Number: 61

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /var/www/html/application/1.1.0/core/MY_Controller.php:95)

Filename: cookie/cookie.php

Line Number: 61

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /var/www/html/application/1.1.0/core/MY_Controller.php:95)

Filename: cookie/cookie.php

Line Number: 61

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /var/www/html/application/1.1.0/core/MY_Controller.php:95)

Filename: cookie/cookie.php

Line Number: 61