Javascript: Is the call to a method / function in a constructor function permitted?


I was wondering if its allowed in JavaScript to call functions or methods in the process of constructing objects with a constructor function since its job is just to create objects.


function Animal(name) { = name;

  alert("I am called in the constructor-function. Is it allowed?");

var x = new Animal("Bird");

This works fine (it will create the Object and alert the message) but is it ok to do this?


Constructors are just like any other function, except they setup the object. You can call anything you need/want to from them (in certain cases/languages even another constructor of that object)

for debugging purposes in JavaScript, alerts are fine.