This and protoype javascript

Why does the warning (d.prototype) return undefined? Should the prototype be animaL?

function Dog(){ } function Animal(){ this.name = "name"; } Dog.prototype = new Animal(); var d = new Dog(); alert(d.constructor); alert(d.prototype); alert(d.name); 
+4
source share
5 answers

The prototype property is a property of the constructor function. This is not a property of objects created using this constructor function.

Inside, any object should know what its prototype is, but it does not appear as a property with a name.

In some implementations, a strange name may be given. It is called __proto__ in Firefox, but obviously you cannot rely on what works in any other browser.

http://www.packtpub.com/article/using-prototype-property-in-javascript

+3
source

d is an instance to use the prototype:

 d.constructor.prototype; 
+1
source

I think the picture at http://mckoss.com/jscript/object.htm describes it (I never remember that myself). Firefox has the __proto__ property, which refers to the prototype, but in addition, the transition from the instance to the prototype is not performed (except for checking with instanceof ).

Prototype drawing

Image is borrowed from the above URL.

0
source

FF and chrome can provide a parent in __proto__ , which can be accessed using d.__proto__

0
source

You cannot use Dog.prototype = new Animal(); Try: Dog.prototype = Animal; .

-1
source

All Articles