I know that in Javascript we can create ,instatnces of object like
var ins = new myObject();
I know that ,window ,document etc are predefined objects in javascript..Can we create new instances of these objects.?
For ex:
Is
var inss = new document();
possible?
Don’t confuse objects with constructors (or classes in most OOP languages). In JavaScript, you create objects by calling constructor functions using the
newoperator:Afterwards you can access the constructor given the object using the
constructorproperty:Theoretically, you can create new objects of the same type as a given object:
In your case, you might try the same with “built-in” object, but it will probably not work since the script engine might forbid it. For example, Chrome will throw
TypeError: Illegal constructorwhen trying to create a new document usingnew document.constructor(). This is becausedocument‘s constructor,HTMLDocument, is not meant to be used directly.