Aklımda Kalası Kelimeler

* давайте работать вместе
* Zarf ve Mazruf, Zerafet(xHoyratlık) ile aynı kökten(za-ra-fe) gelir
* Bedesten
* Suç subuta ermiştir - Suç sabit olmuştur
beforeSend etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
beforeSend etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

7 Nisan 2010 Çarşamba

Javascript ile class tanımı ve metottan fonksiyona parametre geçirerek çağırma

Sınıf tanımı ve public, private ayrımları


Nesne üzerinden yeni property eklemek








Bu da benden bir örnek:
<script type="text/javascript">
function Ogrenci(adi, soyadi, numarasi) {
this.Adi = adi;
this.Soyadi = soyadi;
this.Numarasi = numarasi;
}

Ogrenci.prototype.f_Ekle = function
(f_Basarili, prmB, f_Hatali, prmH) 
{
alert(this.Adi);

//f_Basarili != undefined
//   aynıdır
//f_Basarili != null
if (f_Basarili != undefined) {
f_Basarili.call(this, "Basarilidan =>" + prmB);
}

if (f_Hatali != null) {
f_Hatali.call(this, "Hatalidan =>" + prmH);
}
}


function Basarili(prmBasarili) {
alert("Fonk. Başarılı: " + prmBasarili);
}

function Hatali(prmHatali) {
alert("Fonk. Hatalı: " + prmHatali);
}

var ogr = new Ogrenci("Cem", "Topkaya", 123);

// Her iki metoduda çağırmak istesek
ogr.f_Ekle(Basarili, " _Başarılıya_", Hatali, " _Hatalıya_");

ogr.f_Ekle(null, undefined, Hatali, " _Hatalıya_");

// Hataliyi cagirmadan metodu tetikleyelim.
ogr.f_Ekle(Basarili, " _Başariliya_"); 
</script>



Bu da ajax eventleri ile ilgili özet örneğim:
<script type="text/javascript">
$(document).bind("ajaxSend", function() {
// global event bind edilir 
// local before'dan sonra çalışacak
alert("ajax send bind edilmiş");
}).bind("beforeSend", function() {
//alert Çalışmayacak
alert("local event global gibi bind edilemez");
}).bind("ajaxSuccess", function() {
// global event bind edilir [çalışacak]
alert("ajaxSuccess binde edilmiş");
}).bind("ajaxComplete", function() {
// global event bind edilir [çalışacak]
alert("complete binde edilmiş");
});

// Ajax send olduğunda ve complete olduğunda 
// otomatik çalışsın diye güzel bir örnek.
// Ama global event lerde böyle bir bağlamanın
// olabileceğinin altını bir kez daha çizelim.
$("#loading").bind("ajaxSend", function(){
$(this).show();
}).bind("ajaxComplete", function(){
$(this).hide();
});


function TabloEkleri(
_tabloEkId,
_refEkId,
_refTabloPKId, _refTabloId,
_ekMetni, _anaResim, _sirasi) {

this.TabloEkId = _tabloEkId;
this.RefEkId = _refEkId;
this.RefTabloPKId = _refTabloPKId;
this.RefTabloId = _refTabloId;
this.EkMetni = _ekMetni;
this.AnaResim = _anaResim;
this.Sirasi = _sirasi;
}

TabloEkleri.prototype.f_Ekle = function(fBefore, fSuccess, fComplete, fError) {
// $.ajaxSetup metodu ile $.ajax içinde 
// eventleri bağlamamız gerekmez.
$.ajaxSetup({
beforeSend: fBefore,
complete: fComplete,
success: fSuccess,
error: fError
});
// Ya da $.ajaxSetup metodunu bir fonk. içine alarak
// fAjaxSetup(fBefore, fSuccess, fError, fComplete);
// şeklinde çağırabiliriz. Böylece aşağıdaki
// event bağlamalarına gerek kalmadığı gibi
//
// $.ajax({
//        type: "get",
//        contentType: "application/json; charset=utf-8",
//        url: "hihi.txt",
//        data: "{}",
//        dataType: "json",
// });
//
// şeklinde bir ajax metot çağrısı yapılabilir.
//
// Ama biz aşağıdaki gibi iki yöntemlede (yorum satırı 
// yapılmışlar ve açık satırlar olarak) ajax çağrısını
// görelim.

$.ajax({
type: "get",
contentType: "application/json; charset=utf-8",
url: "hihi.txt",
data: "{}",
dataType: "json",
//              beforeSend: function() {
//                    if (fBefore != undefined) {
//                        fBefore.call();
//                    }
//              },
beforeSend: fBefore,
//              success: function(data, textStatus, XMLHttpRequest) {

//                    if (fSuccess != undefined) {
//                        fSuccess.call(this, data);
//                    }
//                    /**
//                    if (data.d.Sonuc) {
//                    $.fn.colorbox({ html: data.d.Basarili });
//                    return;
//                    } else {
//                    $.fn.colorbox({ html: data.d.Hatali });
//                    }
//                    */
//              },
success: fSuccess,
//                error: function(XMLHttpRequest, textStatus, errorThrown) {
//                    //f_AjaxError(XMLHttpRequest, textStatus, errorThrown);

//                    if (fError != undefined) {
//                        fError.call(this, XMLHttpRequest, textStatus, errorThrown);
//                    }
//                    return;
//                },
error: fError,
//              complete: function(data) {
//                  if (fComplete != undefined) {
//                      fComplete.call(this, data),
//                  }
//              }
complete: fComplete
});
}        
</script>

<script type="text/javascript">
var tbl = new TabloEkleri(1, 2, 3, 4, "metin", 1, 666);

function before() {
alert("beforeeee");
}

function success(data, textStatus, XMLHttpRequest) {
alert("successsss: " + data);
}

function complete(data) {
alert("completeeeee");
}

tbl.f_Ekle(null, success, complete, null);
</script>



Ref:stackoverflow.com

Actually, your code will pretty much work as is, just declare your callback as an argument and you can call it directly using the argument name.
The basics

function doSomething(callback) {
// ...

// Call the callback
callback('stuff', 'goes', 'here');
}

function foo(a, b, c) {
// I'm the callback
alert(a + " " + b + " " + c);
}

doSomething(foo);

That will call doSomething, which will call foo, which will alert "stuff goes here".

Note that it's very important to pass the function reference (foo), rather than calling the function and passing its result (foo()). In your question, you do it properly, but it's just worth pointing out because it's a common error.
More advanced stuff

Sometimes you want to call the callback in a specific context -- e.g., so the this value inside the callback has a specific value. You can easily do that with the JavaScript call function:

function Thing(name) {
this.name = name;
}
Thing.prototype.doSomething = function(callback) {
// Call our callback, but using our own instance as the context
callback.call(this);
}

function foo() {
alert(this.name);
}

var t = new Thing('Joe');
t.doSomething();  // Alerts "Joe" via `foo`

You can also pass parameters:

function Thing(name) {
this.name = name;
}
Thing.prototype.doSomething = function(callback, salutation) {
// Call our callback, but using our own instance as the context
callback.call(this, salutation);
}

function foo(salutation) {
alert(salutation + " " + this.name);
}

var t = new Thing('Joe');
t.doSomething('Hi;');  // Alerts "Hi Joe" via `foo`

Sometimes it's useful to pass the arguments you want to give the callback as an array, rather than individually. You can use apply to do that:

function Thing(name) {
this.name = name;
}
Thing.prototype.doSomething = function(callback) {
// Call our callback, but using our own instance as the context
callback.apply(this, ['Hi', 3, 2, 1]);
}

function foo(salutation, three, two, one) {
alert(salutation + " " + this.name + " - " + three + " " + two + " " + one);
}

var t = new Thing('Joe');
t.doSomething('Hi;');  // Alerts "Hi Joe - 3 2 1" via `foo`