All Questions
Tagged with constructors javascript
4 questions
1
vote
1
answer
354
views
ES6 - Where is it better to initialize a member - parent class or derived class?
I am trying to figure out if there is a better practice for initializing class members of derived classes in ES6 - in the child or the parent, and why?
For example:
Option 1:
class AbstractAnimal {...
3
votes
1
answer
340
views
Is it bad to access the constructor prototype within the constructor?
Most places where I have seen prototypes defined for a constructor it was done like so.
var Person = function(){
this.stuff = stuff;
}
Person.prototype.doSomething = function(){console.log("...
0
votes
0
answers
1k
views
validating arguments in javascript constructors
In many cases, it is useful to have a constructor or factory method that validates arguments before instantiating an object, returning a new object if the arguments are valid and null otherwise.
But ...
2
votes
1
answer
1k
views
Why does JavaScript console.log of objects sometimes show prototype/constructor pattern forever
I've always noticed this, but never actually understood what's happening here. I have a fairly simple object that I've put in a console.log. It has a seemingly never ending pattern of prototype -> ...