Изменить объект JQuery

0

У меня есть плагин JQuery, создающий новый объект каждый раз, когда я вызываю главную функцию плагина:

Вызов функции:

new BpNotification( options );

Сама функция:

function BpNotification( options ) { 
    this.init();
}

BpNotification.prototype = {
    init: function() {

        this.t = setTimeout(function(){}, 5000);

    }
}

Можно ли изменить этот параметр таймаута "t" из "снаружи" после создания объекта?

Теги:

2 ответа

1
Лучший ответ

Вы можете изменить 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);

DEMO

0

Вы хотели бы создать функцию setter для изменения значения setTimeout в объекте прототипа:

BpNotification.prototype = {
    init: function() {
    },
    updateTimeout: function(newVal){
        this.t = setTimeout(function(),newVal);
    }
};

var bpNot = new BpNotification();

bpNot.init();
bpNot.updateTimeout(10000);

Ещё вопросы

Сообщество Overcoder
Наверх
Меню