Skip to content

Commit 0288840

Browse files
committed
pattersn eslint cleaned
1 parent f9a3b91 commit 0288840

File tree

6 files changed

+171
-168
lines changed

6 files changed

+171
-168
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"no-unused-expressions": ["error", { "allowShortCircuit": false, "allowTernary": true }],
99
"no-param-reassign": [0],
1010
"object-shorthand": ["error", "never"],
11-
"no-underscore-dangle": [0]
11+
"no-underscore-dangle": [0],
12+
"wrap-iife": [0]
1213
},
1314
"env": {
1415
"es6": true,

patterns/class.js

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,58 @@
44
* @author: Thorsten Kober
55
66
*/
7-
(function(){
8-
function Base(id){
9-
var _id = id;
10-
11-
this.getId = function(){
12-
return _id;
13-
}
14-
15-
this.setId = function(value){
16-
_id = value;
17-
}
18-
19-
this.init = function(){
20-
console.log("init()");
21-
}
22-
23-
}
24-
window.Base = Base;
7+
(function () {
8+
function Base(id) {
9+
let _id = id;
10+
11+
this.getId = function () {
12+
return _id;
13+
};
14+
15+
this.setId = function (value) {
16+
_id = value;
17+
};
18+
19+
this.init = function () {
20+
console.log('init()');
21+
};
22+
}
23+
window.Base = Base;
2524
})();
2625

27-
(function(){
28-
function ExtendedBase(id){
29-
var _super = new window.Base(id);
30-
31-
var _name;
26+
(function () {
27+
function ExtendedBase(id) {
28+
const _super = new window.Base(id);
29+
let _name;
3230

33-
for(var name in _super){
34-
this[name] = _super[name];
35-
}
31+
/* eslint-disable-next-line */
32+
for (let name in _super) {
33+
this[name] = _super[name];
34+
}
3635

37-
this.setName = function(value){
38-
_name = value;
39-
}
36+
this.setName = function (value) {
37+
_name = value;
38+
};
4039

41-
this.getName = function(){
42-
return _name;
43-
}
40+
this.getName = function () {
41+
return _name;
42+
};
4443

45-
this.constructor = window.Base;
46-
}
47-
window.ExtendedBase = ExtendedBase;
44+
this.constructor = window.Base;
45+
}
46+
window.ExtendedBase = ExtendedBase;
4847
})();
4948

50-
var b = new window.Base("foo");
49+
const b = new window.Base('foo');
5150
b.init();
5251
console.log(b.getId());
53-
b.setId("baba");
52+
b.setId('baba');
5453
console.log(b.getId());
55-
console.log("--------------------");
54+
console.log('--------------------');
5655

57-
var c = new window.ExtendedBase("baba");
56+
const c = new window.ExtendedBase('baba');
5857
c.init();
5958
console.log(c.getId());
60-
c.setName("bo");
59+
c.setName('bo');
6160
console.log(c.getName());
62-
console.log("--------------------");
61+
console.log('--------------------');

patterns/delegation.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@
55
66
*/
77

8-
if(!Object.create){
9-
Object.create = function(o){
10-
function F(){}
8+
if (!Object.create) {
9+
Object.create = function (o) {
10+
function F() {}
1111
F.prototype = o;
1212
return new F();
13-
}
13+
};
1414
}
1515

16-
var Base = {
17-
init:function(id){
16+
const Base = {
17+
init: function (id) {
1818
this.id = id;
1919
},
20-
getId:function(){
20+
getId: function () {
2121
return this.id;
22-
}
23-
}
22+
},
23+
};
2424

25-
var ExtendedBase = Object.create(Base);
26-
ExtendedBase.setName = function(name){
27-
this.name = name;
28-
}
29-
ExtendedBase.getName = function(){
30-
return this.name;
31-
}
25+
const ExtendedBase = Object.create(Base);
26+
ExtendedBase.setName = function (name) {
27+
this.name = name;
28+
};
29+
ExtendedBase.getName = function () {
30+
return this.name;
31+
};
3232

33-
var b = Object.create(Base);
34-
b.init("foo");
33+
const b = Object.create(Base);
34+
b.init('foo');
3535
console.log(b.getId());
36-
console.log("--------------------");
36+
console.log('--------------------');
3737

38-
var c = Object.create(ExtendedBase);
39-
c.init("baba");
38+
const c = Object.create(ExtendedBase);
39+
c.init('baba');
4040
console.log(c.getId());
41-
c.setName("bo");
41+
c.setName('bo');
4242
console.log(c.getName());
43-
console.log("--------------------");
43+
console.log('--------------------');

patterns/functional.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,42 @@
55
66
*/
77

8-
function base(id){
9-
var _id = id;
8+
function base(id) {
9+
const _id = id;
1010

1111
return {
12-
getId:function(){
12+
getId: function () {
1313
return _id;
1414
},
15-
init:function(){
16-
console.log("init()");
17-
}
18-
}
19-
}
20-
21-
function extendedBase(id){
22-
var _base = base(id);
23-
var _name;
24-
25-
_base.setName = function(value){
26-
_name = value;
27-
}
28-
_base.getName = function(){
29-
return _name;
30-
}
31-
return _base;
32-
}
33-
34-
var b = base("foo");
15+
init: function () {
16+
console.log('init()');
17+
},
18+
};
19+
}
20+
21+
function extendedBase(id) {
22+
const _base = base(id);
23+
let _name;
24+
25+
base.setName = function (value) {
26+
_name = value;
27+
};
28+
29+
_base.getName = function () {
30+
return _name;
31+
};
32+
33+
return _base;
34+
}
35+
36+
const b = base('foo');
3537
b.init();
3638
console.log(b.getId());
37-
console.log("--------------------");
39+
console.log('--------------------');
3840

39-
var c = extendedBase("baba");
41+
const c = extendedBase('baba');
4042
c.init();
4143
console.log(c.getId());
42-
c.setName("bo");
44+
c.setName('bo');
4345
console.log(c.getName());
44-
console.log("--------------------");
46+
console.log('--------------------');

patterns/module.js

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,59 @@
55
66
*/
77

8-
var Module = (function(){
9-
var _privateVar = "foo";
10-
11-
function privateFunction(){
12-
console.log("privateFunction()");
13-
}
14-
15-
return {
16-
setPrivateVar:function(value){
17-
_privateVar = value;
18-
},
19-
getPrivateVar:function(){
20-
return _privateVar;
21-
},
22-
publicFunction:function(){
23-
console.log("publicFunction()");
24-
},
25-
callPrivateFunction:function(){
26-
privateFunction();
27-
}
28-
}
8+
const Module = (function () {
9+
let _privateVar = 'foo';
10+
11+
function privateFunction() {
12+
console.log('privateFunction()');
13+
}
14+
15+
return {
16+
setPrivateVar: function (value) {
17+
_privateVar = value;
18+
},
19+
getPrivateVar: function () {
20+
return _privateVar;
21+
},
22+
publicFunction: function () {
23+
console.log('publicFunction()');
24+
},
25+
callPrivateFunction: function () {
26+
privateFunction();
27+
},
28+
};
2929
})();
3030

31-
//example
31+
// example
3232
Module.publicFunction();
3333
console.log(Module.getPrivateVar());
34-
console.log(Module._privateVar); //undefined
35-
36-
var ModuleTwo = (function(){
37-
var _privateVar = "foo";
38-
39-
function privateFunction(){
40-
console.log("privateFunction()");
41-
console.log(publicInterface.getPrivateVar());
42-
}
43-
44-
var publicInterface = {
45-
setPrivateVar:function(value){
46-
_privateVar = value;
47-
},
48-
getPrivateVar:function(){
49-
return _privateVar;
50-
},
51-
publicFunction:function(){
52-
console.log("publicFunction()");
53-
privateFunction();
54-
}
55-
};
56-
57-
return publicInterface;
34+
console.log(Module._privateVar); // undefined
35+
36+
const ModuleTwo = (function () {
37+
let _privateVar = 'foo';
38+
let publicInterface;
39+
40+
function privateFunction() {
41+
console.log('privateFunction()');
42+
console.log(publicInterface.getPrivateVar());
43+
}
44+
45+
publicInterface = {
46+
setPrivateVar: function (value) {
47+
_privateVar = value;
48+
},
49+
getPrivateVar: function () {
50+
return _privateVar;
51+
},
52+
publicFunction: function () {
53+
console.log('publicFunction()');
54+
privateFunction();
55+
},
56+
};
57+
58+
return publicInterface;
5859
})();
5960

60-
//example
61+
// example
6162
ModuleTwo.publicFunction();
62-
console.log(ModuleTwo._privateVar); //undefined
63+
console.log(ModuleTwo._privateVar); // undefined

0 commit comments

Comments
 (0)