The object has a method written to the prototype:
ServisePlate.prototype.disclose = function() { console.log('запустилась функция disclose'); function showBody() { if(this.elem.offsetHeight < (this.body.offsetHeight + this.initialSize)) { this.elem.style.height = this.elem.offsetHeight + this.settings.step + 'px'; setTimeout(showBody.call(this), this.settings.speed); } } function hideBody() { if(this.elem.offsetHeight > this.initialSize) { this.elem.style.height = this.elem.offsetHeight - this.settings.step + 'px'; setTimeout(hideBody.call(this), this.settings.speed); }else { this.elem.style.height = ''; } } if(this.elem.offsetHeight == this.initialSize || this.elem.offsetHeight >= (this.body.offsetHeight + this.initialSize)) { if(this.elem.offsetHeight == this.initialSize) { console.log('Сработало условие 1'); showBody.call(this); } else { console.log('Сработало условие 2') hideBody.call(this); } } } It has two internal functions, hideBody and showBody .
How to attach object context to them? Via call(this) , as in the code above, all functions are started and executed except for the variables declared in the constructor - this is an object:
this.settings = { step: 30, speed: 1000 } its properties define the pixel increment step and the restart timeout. So I work the functions as if they are not there ..... although from these functions their values are derived via console.log .
In theory, with such values every second 30px should be added to the height property, but the desired height is obtained instantly, without smooth addition.
Through apply everything happens exactly the same, and functions do not run at all through bind .
How to be?