<div id="block1"></div>
window.onload = function(e){
new myPlugin({
id: "#block1",
//params
});
function myPlugin(param){
this.obj = document.getElementById(param.id);
var param1 = 100;
var param2 = 200;
this.method2 = function(){
},
this.method2 = function(){
}
}
}
var myPlugin = {
param1: 100,
param2: 200,
method1: function(){
},
method2: function(){
}
}
<div id="gallery1">
<input type="button" class="btn1" value="-">
<input type="button" class="btn2" value="+">
<div class="result">0</div>
</div>
<div id="gallery2">
<input type="button" class="btn1" value="-">
<input type="button" class="btn2" value="+">
<div class="result">0</div>
</div>
function Slider(el){
this.main = document.getElementById(el.id);
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--;
}
this.updateResult();
};
this.method2 = function(){
this.speed++;
this.updateResult();
};
this.btn1.addEventListener('click', this.method1.bind(this));
this.btn2.addEventListener('click', this.method2.bind(this));
}
new Slider({
id: "gallery1"
});
new Slider({
id: "gallery2"
});
function myPlugin(param) {
var id = param.id;
return {
param1: 100,
param2: 200,
method1: function () {
return id;
},
method2: function () {}
}
}
var plg = myPlugin({
id: "#block1"
})
console.log(plg.method1()); //> "#block1"