, this.getTimeCardData(), , .
, this . , , JavaScript this , , , , this - .
:
TimeCard.prototype = {
doSomething: function() {
someArray.forEach(function() {
this.getTimeCardData();
});
}
};
this.doSomething(); TimeCard, this timecard. forEach this timecard. ; ajax ..
, this :
TimeCard.prototype = {
doSomething: function() {
var thisCard = this;
someArray.forEach(function() {
thisCard.getTimeCardData();
});
}
};
, . , selectAll getTimeCardData. , selectAll this? , :
$('#container').on('click', '#selectAll', tc.selectAll);
, selectAll, this DOM, .
:
jQuery, $.proxy, , this, , this :
$('#container').on('click', '#selectAll', $.proxy(tc.selectAll, tc));
ES5 Function#bind, . , IE8 , " ES5" (, $.proxy , , ):
$('#container').on('click', '#selectAll', tc.selectAll.bind(tc));
( , ):
( ):
$('#container').on('click', '#selectAll', function() {
tc.selectAll();
});
this, DOM. , , , , currentTarget. , tc.selectAll this, tc , this ( DOM, ) :
$('#container').on('click', '#selectAll', function(e) {
tc.selectAll(e.currentTarget);
});
, , , TimeCard.prototype. , , new TimeCard() , TimeCard.prototype, , .
, , prototype . , :
function TimeCard(){
this.date = new Date();
this.pay_period_begin = null;
this.pay_period_end = null;
}
TimeCard.prototype.getTimeCardData = function(){
};
: . prototype, , new TimeCard(), , , , .
, , :
var TimeCard = (function() {
function TimeCard(){
this.date = new Date();
this.pay_period_begin = null;
this.pay_period_end = null;
}
TimeCard.prototype.getTimeCardData = function(){
};
return TimeCard;
})();
... , .