Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Worker (name, office, salary, city) {
- this.name = name;
- this.office = office;
- this.salary = salary;
- this.city;
- }
- // builder pattern
- function WorkerBuilder() {
- var name = 'default name';
- var office = 'Goyello';
- var salary = 300;
- var city = 'Sosnowiec';
- return {
- name: function(name) {
- name = name;
- return this;
- },
- age: function(age) {
- age = age;
- return this;
- },
- office: function(office) {
- office = office;
- return this;
- },
- city: function(city) {
- city = city;
- return this;
- },
- build: function() {
- var worker = new WorkerBuilder(this);
- return worker;
- }
- }
- }
- var tomasz = new WorkerBuilder()
- .name('Tomasz')
- .age(29)
- .office('Facebook')
- .city('Sopot')
- .build();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement