If I add a function in the "constructor", I can extend it with an other function like so:
var MyClass = function() {
this.time = function() { return 4.5; }
this.time.formatted = function() { return format(this.time(), "HH:mm"); }
}
I can't figure out a nice way to do this if I create the function in prototype like so:
var MyClass = function() {}
MyClass.prototype = {
time: function() { return 4.5; },
time.formatted: function () { ... } // This does not work!
}
MyClass.prototype.time.formatted = function() { ... }
// the line above works but I don't like it since it separates everything.
// e.g. if I have 15 functions inside prototype, the .formatted will be like
// 50 lines apart from the time: function
*Edit: * On second thoughts the line above does not work, adding the .formatted messes the reference to this. Perhaps solvable?
Any tips? Thanks!
this.time = new TimeFormatter();