Can I do something like?:
function User(form) {
this._username = form.username.value;
this._password = form.password.value;
this._surname = form.surn
No you can't, JavaScript does not support overloading of any kind.
What you can do is either pass an object which has already been populated with the values into your constructor and then grab the values from the object, but this which duplicates code.
Or you can create a default constructor and add methods such as initFromUser
or setFromForm
which then take the respective parameters and setup the objects values, new User().initFormForm(form)
looks pretty clean to me.