Exitos
Exitos

Reputation: 29750

How do I initialise static variables in javascript static class?

I have a static class in javascript...

var Logger = {
    logtofirefox: function (str, priority) {

         console.log(str);        

    },
    logtoie: function (str, priority) {

         alert(str);        

    }

}

I call it like this from another file...

Logger.log('Hello World');

But I want to inject the string 'log : ' before the words 'Hello World' on all functions.

Wondering if this is possible with minimum fuss?

Upvotes: 0

Views: 108

Answers (1)

Manse
Manse

Reputation: 38147

Just update the output for each function :

var Logger = {
    logtofirefox: function (str, priority) {
         console.log('log : ' + str);        
    },
    logtoie: function (str, priority) {
         alert('log : ' + str);        
    }
};

Upvotes: 1

Related Questions