Can someone explain the purpose of this function? I've been searching for information but can't find anything.
I tested it in Firefox:
window.constructor()
// TypeError: Illegal constructor
new window.constructor()
// TypeError: Illegal constructor
In NodeJS, it simply returns an empty object:
constructor()
// {}
Just to provide context as to why I'm asking, I'm encountering an issue with my Scheme interpreter when using similar code in NodeJS:
(define-class Foo (constructor (lambda (self) (print "<new>"))))
The problem arises because the parent object is missing. In NodeJS, constructor()
will return a function if used like this:
constructor(function foo() { })
// [Function: foo]
As a result, my code checking whether the parent is a function fails in NodeJS.
I don't know how to revise my define-class
function, but I'm simply trying to understand what constructor()
does and if there is any documentation available for it.