mardi 30 décembre 2014

Create objects inside a module javascript

I am learning design patterns in javascript but I have a problem creating a module. I am creating a Person object inside of module and I have combined it with a constructor pattern, just beacuse I am learning it too, but nothing happens.


Can anybody help me, I don't undertand my mistake here



var myModule = (function () {
function Person(id, name) {
this.id = id;
this.name = name;
}

Person.prototype.toString = function () {
return "\nID: " + this.Id + "\nName: " + this.name;
};

return {
newPerson: function (id, name) {
return new Person(id,name);
console.log(Person.toString());
}
};
})();

var x = myModule;

x.newPerson(1, "John");

Aucun commentaire:

Enregistrer un commentaire