0

I have a JQuery plugin creating a new object each time I call the plugin's main-function:

Function call:

new BpNotification( options );

Function itself:

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

BpNotification.prototype = {
    init: function() {

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

    }
}

Is it possible to modify this timeout-option "t" from 'outside' after the object is created?

1
  • You code is unclear and contains syntax errors at the end. In which context that setTimeout occurs? Commented Sep 28, 2013 at 13:52

2 Answers 2

1

You can change t as you like:

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

Sign up to request clarification or add additional context in comments.

Comments

0

You would want to create a setter function to change the setTimeout value, in the prototype object:

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

var bpNot = new BpNotification();

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.