Re: Class prototype readonly

Skip to first unread message

Nicholas Zakas

May 1, 2020, 11:00:29 AM5/1/20
Nicholas, not Nic. :)

The prototype property cannot be overwritten, so PersonClass.prototype cannot be set to a different object. The prototype can still be modified.

for-in iterates over both own and prototype properties that are enumerable. getOwnPropertyNames returns only own properties but returns both enumerable and non enumerable properties. 

On Wed, Apr 29, 2020 at 8:20 PM Jeff <> wrote:
Hi Nic,

1st question, On page 167, the only note says the prototype of a class is readonly, but I tried with following code, it works well,

class PersonClass {
constructor(name) { = name;

sayName() {

/* method or property could be assigned on the prototype
same as declaring class with function */
PersonClass.prototype.anotherFunc = function () {
console.log(this, 'another func');
PersonClass.prototype.age = 9;

let person = new PersonClass('jeff');

/* special note: for-in and getOwnPropertyNames are diff
for-in only gets props on prototype, getOwnPropertyNames
only gets instance attr */
for (const key in person) {

2nd question, as my comments show, for-in only gets all the props on prototype of a class, and Object.getOwnPropertyNames only gets attrs on the instance. I am asking that cuz you probably know it and I couldn't find a good answer for that online. 

thx & brs,

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
To view this discussion on the web visit


May 13, 2020, 4:25:36 AM5/13/20
to Zakas Books
Thanks Nicolas :-)
To unsubscribe from this group and stop receiving emails from it, send an email to
Reply all
Reply to author
0 new messages