javascript - Why is this property defined on the prototype--not on the constructor? -


In the chapter, I found the following part of the code. I would like to know why the author has determined the name property on the prototype - not in the manufacturer.

function input error (message) {this.message = message; This.stack = (new error ()). Stack; } InputError.prototype = Object.create (Error.prototype); InputError.prototype.name = "InputError";

During the book, he is defining properties in protoptip on the creator and methods. Nicholas Jacques recommends doing this for web developers in the professional JavaScript ch6, because they say, if you define methods in constructor, then construct a new example of the method by calling each constructor the constructor. it happens. This is definitely the opposite position - a property defined on the property.

To repeat: What should I know, Why can the author define 'name' property on prototype ?

So far, I have read these two SO posts, not two benefits.

- It tells me what I have already done in the books mentioned above.

- I did not really understand this post, but I think it was irrelevant because it was talking about patterns in other languages. I'm worried about javascript.

Why did the author define 'name' property prototype?

Because InputError shares name as each example is "methods" is only an interactive term for the properties, which have The value is in the form of a (*) function. Usually these methods should be shared between instances, but in some cases (like this one) this data may also be.


*: Meaning, there is no difference between the property and method .


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -