Tuesday 16 May 2017

Firing event outside class scope javascript

I have a class :

var psTesting = (function(){

var privatevariable;

function setVariable(value){
    privatevariable = value;
    console.log('the variable value is ' + value);
}

function dismiss ( callback ) {
    console.log('entro dismiss')
    if( callback ) callback();
    if( this.onDismiss ) this.onDismiss();
}

return  {
    pVariable : function(val) {
        setVariable(val)
    }
}
})();

psTesting.pVariable(22);

psTesting.onDismiss = function(){
console.log('this is a onDismiss test');
}

I want to be able to fire the onDismiss function from outside of the class psTesting.onDismiss()

I have been trying playing with the .call .apply .bind stuff with no luck.

Thanks, PA



via Pedro de la Cruz

No comments:

Post a Comment