Answer the question
In order to leave comments, you need to log in
Prototype constructor?
Hello.
1) Does it make sense to specify a prototype constructor for a child object, as I understand it, this is only a function reference, and if it is not necessary to use it?
proto = { color: green }
const Son = function( name ) { }
Son.prototype = Object.create( proto )
Son.prototype.constructor = Son //
Son.prototype = Object.create( proto, { constructor: { value: Son }, foo: { writable: false, configurable: false, value: 'привет' } } )
Son.prototype = Object.create( proto );
Son.prototype.constructor = Son;
Son.prototype.foo = 'привет';
Son.prototype.test= function() { return this };
Son.prototype.test1= function() { return this };
Son.prototype.test2= function() { return this };
Son.prototype.test3= function() { return this };
Son.prototype.test4= function() { return this };
Son.prototype.test5= function() { return this };
Answer the question
In order to leave comments, you need to log in
Does it make sense to specify a prototype constructor for a child object, as I understand it, this is only a function reference, and if it is not necessary to use it?Every constructor has a prototype. The default is Object.prototype.
What is the best way to add custom properties to the prototypeI don't know. IMHO, for applied tasks it is better to do so that it is easier to read.
What is the best way to add your own methods, is it the only option, or is there a more elegant solution, for example, create an object with your own methods and glue it with a prototype?It doesn't matter, but there's one thing to keep in mind.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question