[oopinjs] The [[Prototype]] Property, assign a value to a prototype property

12 views
Skip to first unread message

michail

unread,
Aug 3, 2018, 9:12:33 AM8/3/18
to Zakas Books

Hi,

at the end of the "The [[Prototype]] Property", you say

"This example also highlights an important concept: You cannot assign a value to a prototype property from an instance. ”

Excerpt From: Nicholas C. Zakas. “The Principles of Object-Oriented Javascript.” iBooks. 

 

But actually you can do object.__proto__.toString = function() { return '[object Custom2]'; },  object.__proto__.prop1 = 10, or object.__proto__.f1 = function() { return 10; }

Is it something which I am missing or you have some something else in mind?

Nicholas Zakas

unread,
Aug 3, 2018, 2:52:42 PM8/3/18
to zakas...@googlegroups.com
Hi Michail,

What you're describing is not assigning a value to a prototype property through the instance. Instead, you are using the instance to get a reference to the prototype object and then modifying the property directly on the prototype. It's the same as using Object.getPrototypeOf() to retrieve the prototype and then modify it directly.

--
You received this message because you are subscribed to the Google Groups "Zakas Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zakasbooks+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

______________________________
Nicholas C. Zakas
@slicknet

Author, Principles of Object-Oriented JavaScript

Mihail Stefanov

unread,
Aug 4, 2018, 3:02:23 AM8/4/18
to zakas...@googlegroups.com
Hi Nicholas,
In that case you are right, there is no way to manipulate  prototype.

By the way really good book!

To unsubscribe from this group and stop receiving emails from it, send an email to zakasbooks+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages