I'm reading the KnockoutJS source code.
I ran into the following line which I'm not sure I understand...
ko.utils = new (function () {
Generally, the structure seems to be along the lines of:
ko.utils = new (function () {
// some variables declared with var
return {
export:value,
export:value
};
})();
I don't understand this construct, why is new
needed? What does it do? What is it useful for?
(I thought that if a function is called with new
before its name it is invoked as a constructor, and if it returns an object it's identical to an invokation without new
.)
UPDATE: I asked the KnockoutJS team on github and this is what I got back:
My guess is that Steve just didn't know that it wasn't needed. Looking back at his original commit, I see a lot of unnecessary news that have since been removed.