我試圖創建一個函數來遍歷一些錶行,但我需要使用this.isempty而不是isempty。我如何在每個循環內部訪問它。OOP - 在每個內部訪問公共「this」
編號:
function checkValues(look) {
this.isempty = 1;
this.search = $(look).find("input").each(function(){
if ($.trim($(this).val())!="") {
this.isempty = 0;
}
});
return this.isempty;
}
顯然this.isempty = 0;
將無法正常工作。我怎樣才能做到這一點?
第一種方法,我意識到使用每個不是最好的辦法,但是是var self = this;正確的方式呢? – FirstLegion 2014-11-24 03:24:16
@FirstLegion AFAIK在這種情況下是最好的方式 – 2014-11-24 03:26:54
好的,謝謝。 – FirstLegion 2014-11-24 03:34:48