function Counter(start){
this.value = start;
this.Up = function()
{
this.value++;
this.ShowText();
console.log(this.value);
};
this.Down = function()
{
this.value--;
this.ShowText;
console.log(this.value);
};
this.ShowText = function()
{
$('.box').text(this.value);
};
this.Render = function()
{
$('#counter-minus').click(this.Down);
$('#counter-plus').click(this.Up);
}
}
counter = new Counter(2);
counter.Render();
<div class="counter">
<span class="control-counter" id="counter-minus">−</span>
<div class="box">2</div>
<span class="control-counter" id="counter-plus">+</span>
</div>
this.Up = function () {
...
}.bind(this);
this.Down = function () {
...
}.bind(this);
this.Render = function () {
$(document)
.on('click', '#counter-minus', this.Down.bind(this))
.on('click', '#counter-plus', this.Up.bind(this));
}
function Counter(start){
var xxx = this;
//А тут везде внутри функций вместо this фтыкаем xxx
}
$('#counter-minus').click(this.Down);
$('#counter-minus').on('click', this.Down.bind(this));
function Counter(start){
var that = this;
this.value = start;
this.Up = function()
{
that.value++;
that.ShowText();
console.log(that.value);
};
this.Down = function()
{
that.value--;
that.ShowText;
console.log(that.value);
};
this.ShowText = function()
{
$('.box').text(this.value);
};
this.Render = function()
{
$('#counter-minus').click(this.Down);
$('#counter-plus').click(this.Up);
}
}
counter = new Counter(2);
counter.Render();