I would like to cheat a little bit when creating prototypes
for example
var person = {
name: 'John',
age: 110,
gender: 'm',
...
};
var employee = new Person(person);
function Person(args) {
$.each(args, function(key, value) {
this[key] = value; // Cannot create property 'key' on number
});
}
console.log(employee.age);
In PHP this can be done like
function __construct() {
$args = func_get_arg(0);
foreach ($args as $key => $value) {
$this->$key = $value;
}
return $this;
}