У меня есть плагин JQuery, создающий новый объект каждый раз, когда я вызываю главную функцию плагина:
Вызов функции:
new BpNotification( options );
Сама функция:
function BpNotification( options ) {
this.init();
}
BpNotification.prototype = {
init: function() {
this.t = setTimeout(function(){}, 5000);
}
}
Можно ли изменить этот параметр таймаута "t" из "снаружи" после создания объекта?
Вы можете изменить t
как вам нравится:
function BpNotification( options ) {
this.init();
}
BpNotification.prototype = {
init: function() {
this.t = setTimeout(function(){alert('default');}, 500);
}
}
var Bpn = new BpNotification();
clearTimeout(Bpn.t);
Bpn.t = setTimeout(function(){alert('updated!');}, 500);
Вы хотели бы создать функцию setter для изменения значения setTimeout в объекте прототипа:
BpNotification.prototype = {
init: function() {
},
updateTimeout: function(newVal){
this.t = setTimeout(function(),newVal);
}
};
var bpNot = new BpNotification();
bpNot.init();
bpNot.updateTimeout(10000);