pokoli/ButiJS — Issue #4: prefer constructors with parameters (src/player.js)
Author: jmgimeno
Created: 2011-11-11 11:23:52+00:00
State: open

Instead of

var Player = function() {
this.name='';
this.email='';
};

and

var p = new Player();
p.name = name;

it is better to

var Player = function(name, email) {
this.name = name;
this.email = email;
}

and if you do not have email, you pass only one parameter.

var p = new Player(name); // email gets undefined

undefined is in the language with the meaning of undefined, which is what it is in this case.

JM