Javascript: Constructing Objects
I'm a bit of a javascript noob, but I have a general question that has been bothering me. Lets take an example: If I hop into a JS console on Chrome, I can easily browse the window
Solution 1:
Any function that is written in JavaScript can be a constructor when called using the new
keyword. As you already noticed the function you are dealing with is native, i.e. written in C or C++ (probably C++ since Chrome's JavaScript engine is written in C++, too). Native functions/objects can have specific behaviour such as your case where you cannot use it as a constructor - there's nothing you can do.
That "function" doesn't even have a .call()
method, you you also cannot call it on an object you created before (not that it would be very useful as it wouldn't have the proper [[Prototype]] set)
Post a Comment for "Javascript: Constructing Objects"