What I would like to have is something like this:
var fnc = new constructor(); // --> function()...
fnc(); // --> Running main function
fnc.method(); // --> Running method
So that one could create new fnc
instances, while having the methods in the constructors prototype. However, I don't seem to be able to have result of the constructor as a function, as regardless of the return clause, it seems to become a object, resulting to ..
Uncaught TypeError: Property 'fnc' of object [object Object] is not a function
:(
Edit: Added example code. So what I'm thinking is along these lines.
var constructor = function() { return function() { console.log('Running main function.') }; };
constructor.prototype.method = function() { console.log('Running method.'); }
var fnc = new constructor();
console.log('constructor: ', constructor);
console.log('fnc: ', fnc);
console.log('fnc.method: ', typeof $.method);
console.log('');
fnc();
fnc.method();
In this case, one gets the...
Uncaught TypeError: Object function () { console.log('Running main function.') } has no method 'method'
...error as the function provided by the constructor is different than the constructor itself, on which prototype chain is tacked on. Just can't seem to wrap my head around this. Did one version with jQuery like initialization, which did the trick alright but I later on found out that it ended up doing it through the empty function prototype, meaning every function got the methods.