Created
July 2, 2012 04:50
-
-
Save renatoargh/3031158 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var personFactory = function(id, name, age){ | |
| var _id = id; | |
| var _name = name; | |
| var _age = age; | |
| var personPrototype = { | |
| getId: function(){ | |
| return _id; | |
| }, | |
| setId: function(id){ | |
| _id = id; | |
| }, | |
| getName: function(){ | |
| return _name; | |
| }, | |
| setName: function(name){ | |
| _name = name; | |
| }, | |
| getAge: function(){ | |
| return _age; | |
| }, | |
| setAge: function(age){ | |
| _age = age; | |
| } | |
| }; | |
| return Object.create(personPrototype); | |
| }; | |
| var renato = personFactory(1, "Renato Gama", 25); | |
| console.log(renato.getName); | |
| var foo = personFactory(2, "Foo Bar", 13); | |
| console.log(foo.getName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment