I completely agree with Boris ... You should look for more information here ( https://www.google.com/search?q=javascript+prototype+chain ), but basically, if you want to view the elements in the DOM object, you just need to do this as described below:
function exploreElement(element){ contentToString = ""; for (var i in element){ contentToString += i + " : " + element[i] + "<br />"; } document.write(contentToString); } exploreElement(document);
Prototype and proto are something completely different ...
If you have a design function like this:
function SomeObject(){ this.__proto__.id = "instance_default_name"; SomeObject.id = "SomeObject";
Then you can add methods to this constructor using a prototype (I assume that you have an empty div with the identifier "myInstance" and another with the identifier "test" in the document):
SomeObject.prototype.log = function(something){ document.getElementById("myInstance").innerHTML += something + "<br />"; }
Add some methods to test:
SomeObject.prototype.setId = function(id){ this.id = id; } SomeObject.prototype.getId = function(){ return this.id; } SomeObject.prototype.getClassName = function(){ return SomeObject.id; }
Then you can create an instance of SomeObject with a new statement and run several such tests:
myInstance = new SomeObject(); myInstance.setId("instance_1"); aDivElement = document.getElementById("test"); aDivElement.style.backgroundColor = "rgb(180,150,120)"; myInstance.log("p1 = " + aDivElement); // [object HTMLDivElement] myInstance.log("p1 backgroundColor = " + (aDivElement.style.backgroundColor)); myInstance.log("myInstance = " + myInstance); // [object Object] an instance of SomeObject myInstance.log("myInstance.constructor = " + myInstance.constructor); // function SomeObject() { this.__proto__.id = "instance_default_name"; SomeObject.id = "SomeObject"; } myInstance.log("myInstance.constructor.prototype = " + myInstance.constructor.prototype); // .prototype WHEN CALLED by the instance NOT __proto__ // The constructor of myInstance is SomeObject and the prototype of SomeObject is the prototype of all instances of SomeObject myInstance.log("myInstance.id = " + myInstance.getId()); // id for the instance of SomeObject that you have instanciated myInstance.log("SomeObject.prototype.id = " + SomeObject.prototype.getId()); // id by default of the prototype myInstance.log("myInstance.constructor.prototype.id = " + myInstance.constructor.prototype.getId()); // id by default of the prototype myInstance.log("myInstance.getClassName() = " + myInstance.getClassName()); // myInstance.getClassName() = SomeObject
I donβt know if this will talk a little with you, but I hope this helps you in your search. Best wishes. Nicolas
source share