Skip to content

Commit 898db2e

Browse files
committed
Linted select2/utils
For the most part this was semicolon fixes, but there was a function, `calledMethod`, which did need to be moved out of the loop.
1 parent ed6eb4f commit 898db2e

3 files changed

Lines changed: 29 additions & 24 deletions

File tree

.jshintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"bitwise": true,
3+
"globals": {
4+
"define": true
5+
},
36
"indent": 2,
7+
"maxlen": 80,
48
"quotmark": "single"
59
}

src/js/jquery.shim.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
define(function () {
22
return jQuery;
3-
})
3+
});

src/js/select2/utils.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ define([], function () {
22
var Utils = {};
33

44
Utils.Extend = function (ChildClass, SuperClass) {
5-
var __hasProp = {}.hasOwnProperty
5+
var __hasProp = {}.hasOwnProperty;
66

77
function BaseConstructor () {
88
this.constructor = ChildClass;
@@ -29,7 +29,7 @@ define([], function () {
2929
for (var methodName in proto) {
3030
var m = proto[methodName];
3131

32-
if (typeof m !== "function") {
32+
if (typeof m !== 'function') {
3333
continue;
3434
}
3535

@@ -68,38 +68,39 @@ define([], function () {
6868
DecoratedClass.prototype = new ctr();
6969

7070
for (var m = 0; m < superMethods.length; m++) {
71-
var methodName = superMethods[m];
71+
var superMethod = superMethods[m];
7272

73-
DecoratedClass.prototype[methodName] = SuperClass.prototype[methodName];
73+
DecoratedClass.prototype[superMethod] =
74+
SuperClass.prototype[methodName];
7475
}
7576

76-
for (var m = 0; m < decoratedMethods.length; m++) {
77-
var methodName = decoratedMethods[m];
77+
var calledMethod = function (methodName) {
78+
// Stub out the original method if it's not decorating an actual method
79+
var originalMethod = function () {};
7880

79-
function calledMethod (methodName) {
80-
// Stub out the original method if it's not decorating an actual method
81-
var originalMethod = function () {};
81+
if (methodName in DecoratedClass.prototype) {
82+
originalMethod = DecoratedClass.prototype[methodName];
83+
}
8284

83-
if (methodName in DecoratedClass.prototype) {
84-
originalMethod = DecoratedClass.prototype[methodName];
85-
}
85+
var decoratedMethod = DecoratorClass.prototype[methodName];
8686

87-
var decoratedMethod = DecoratorClass.prototype[methodName];
87+
return function () {
88+
var unshift = Array.prototype.unshift;
8889

89-
return function () {
90-
var unshift = Array.prototype.unshift;
90+
unshift.call(arguments, originalMethod);
9191

92-
unshift.call(arguments, originalMethod);
92+
return decoratedMethod.apply(this, arguments);
93+
};
94+
};
9395

94-
return decoratedMethod.apply(this, arguments);
95-
}
96-
}
96+
for (var d = 0; d < decoratedMethods.length; d++) {
97+
var decoratedMethod = decoratedMethods[d];
9798

98-
DecoratedClass.prototype[methodName] = calledMethod(methodName);
99+
DecoratedClass.prototype[decoratedMethod] = calledMethod(decoratedMethod);
99100
}
100101

101102
return DecoratedClass;
102-
}
103+
};
103104

104105
var Observable = function () {
105106
this.listeners = {};
@@ -120,8 +121,8 @@ define([], function () {
120121
this.invoke(this.listeners[event], slice.call(arguments, 1));
121122
}
122123

123-
if ("*" in this.listeners) {
124-
this.invoke(this.listeners["*"], arguments);
124+
if ('*' in this.listeners) {
125+
this.invoke(this.listeners['*'], arguments);
125126
}
126127
};
127128

0 commit comments

Comments
 (0)