There is an object c.
It has a function c.log(message)
Is it possible to add some variables for using them like c.log.debug = true?
Javascript is a full object-orientated language. That means that almost everything is an object - even functions :
var f = function(){};
alert(f instanceof Function);
// but this statement is also true
alert(f instanceof Object);
// so you could add/remove propreties on a function as on any other object :
f.foo = 'bar';
// and you still can call f, because f is still a function
f();
With little modification it is possible like this:
var o = {f: function() { console.log('f', this.f.prop1) }};
o.f.prop1 = 2;
o.f(); // f 2
o.f.prop1; // 2
o.f is passed as a parameter(stored as variable etc...)o.f.prop1 which is a read/write property even from outside of o. So it is flexible and may be useful.It won't work like this. You could instead add the 'debug' flag as a parameter to your function, e.g.
c.log = function(message, debug) {
if debug {
// do debug stuff
}
else {
// do other stuff
}
}
cis$.