function Slider(el){
this.main = document.getElementById(el),
this.speed = 0,
this.btn1 = this.main.getElementsByClassName('btn1')[0],
this.btn2 = this.main.getElementsByClassName('btn2')[0],
this.result = this.main.getElementsByClassName('result')[0],
this.updateResult = function(){
this.result.innerHTML = this.speed;
},
this.method1 = function(){
/*if(this.speed > 0){
this.speed--;
}*/
console.log(this.speed); //undefined
},
this.method2 = function(){
//this.speed++;
console.log(this.speed); //undefined
};
this.btn1.addEventListener('click', this.method1);
this.btn2.addEventListener('click', this.method2);
}
new Slider('gallery');
this.updateResult = function(){
this.result.innerHTML = this.speed;
},
this.btn2.addEventListener('click', function(){
this.speed++;
this.updateResult; //не обновляет информацию в самом HTML. Реакции нет.
console.log(this.speed); //выводит NAN.
});
window.onload = function(e){
new Slider('block1');
function Slider(el){
this.main = document.getElementById(el);
this.speed = 0;
this.btn1 = this.main.getElementsByClassName('btn1')[0];
this.btn2 = this.main.getElementsByClassName('btn2')[0];
this.result = this.main.getElementsByClassName('result')[0];
this.updateResult = function(){
this.result = innerHTML(this.speed);
}
this.btn1.addEventListener('click', function(){
if(this.speed > 0){
this.speed--;
}
this.updateResult;
});
this.btn2.addEventListener('click', function(){
this.speed++;
this.updateResult;
});
}
}
(function(window) {
window.MyPlugin = function(element) {
this.element = element;
}
myPlugin.prototype.myMethod = function() {
//...
}
})(window);
var elem = document.getElementById('elem');
var test = new MyPlugin(elem);
test.myMethod();
Основное - нет контроля потока данных.