Permalink
Browse files

Switching to strict equality operators throughout, and removing redef…

…inition of ObjectMethods.
  • Loading branch information...
jcoglan committed Aug 29, 2008
1 parent 05fc85d commit 1d4766f593392b6fdea89ac0c8fe7e95b64574ec
View
@@ -30,7 +30,7 @@ JS = {
extend: function(object, methods) {
methods = methods || {};
for (var prop in methods) {
- if (object[prop] == methods[prop]) continue;
+ if (object[prop] === methods[prop]) continue;
object[prop] = methods[prop];
}
return object;
@@ -95,7 +95,7 @@ JS = {
},
ignore: function(key, object) {
- return /^(include|extend)$/.test(key) && typeof object == 'object';
+ return /^(include|extend)$/.test(key) && typeof object === 'object';
}
};
@@ -136,12 +136,12 @@ JS.extend(JS.Module.prototype, {
else module.included && module.included(options.included || this);
}
else {
- if (typeof inc == 'object') {
+ if (typeof inc === 'object') {
modules = [].concat(inc);
for (i = 0, n = modules.length; i < n; i++)
this.include(modules[i], options);
}
- if (typeof ext == 'object') {
+ if (typeof ext === 'object') {
modules = [].concat(ext);
for (i = 0, n = modules.length; i < n; i++)
(options.included || this).extend(modules[i], false);
@@ -156,7 +156,7 @@ JS.extend(JS.Module.prototype, {
},
includes: function(moduleOrClass) {
- if (Object == moduleOrClass || this == moduleOrClass || this.__res__ === moduleOrClass.prototype)
+ if (Object === moduleOrClass || this === moduleOrClass || this.__res__ === moduleOrClass.prototype)
return true;
var i = this.__inc__.length;
while (i--) {
@@ -171,8 +171,8 @@ JS.extend(JS.Module.prototype, {
for (var i = 0, n = this.__inc__.length; i < n; i++)
this.__inc__[i].ancestors(results);
var klass = (this.__res__||{}).klass,
- result = (klass && this.__res__ == klass.prototype) ? klass : this;
- if (JS.indexOf(results, result) == -1) results.push(result);
+ result = (klass && this.__res__ === klass.prototype) ? klass : this;
+ if (JS.indexOf(results, result) === -1) results.push(result);
return results;
},
@@ -217,7 +217,7 @@ JS.extend(JS.Module.prototype, {
resolve: function(target) {
var target = target || this, resolved = target.__res__, i, n, key, made;
- if (target == this) {
+ if (target === this) {
i = this.__dep__.length;
while (i--) this.__dep__[i].resolve();
}
@@ -228,7 +228,7 @@ JS.extend(JS.Module.prototype, {
this.__inc__[i].resolve(target);
for (key in this.__fns__) {
made = target.make(key, this.__fns__[key]);
- if (resolved[key] != made) resolved[key] = made;
+ if (resolved[key] !== made) resolved[key] = made;
}
}
});
@@ -251,7 +251,7 @@ JS.ObjectMethods = new JS.Module({
method: function(name) {
var self = this, cache = self.__mcache__ = self.__mcache__ || {};
- if ((cache[name] || {}).fn == self[name]) return cache[name].bd;
+ if ((cache[name] || {}).fn === self[name]) return cache[name].bd;
return (cache[name] = {fn: self[name], bd: JS.bind(self[name], self)}).bd;
}
});
@@ -327,7 +327,6 @@ JS.Module.include(JS.ObjectMethods);
JS.Class = JS.extend(new JS.Class(JS.Module, JS.Class.prototype), JS.ObjectMethods.__fns__);
JS.Module.klass = JS.Module.constructor =
JS.Class.klass = JS.Class.constructor = JS.Class;
-JS.ObjectMethods = new JS.Module(JS.ObjectMethods.__fns__);
JS.Module.extend({
_observers: [],
View
@@ -39,7 +39,7 @@ JS.Command = new JS.Class({
},
_restart: function() {
- if (this.pointer == 0 && this._redo && this._redo.execute)
+ if (this.pointer === 0 && this._redo && this._redo.execute)
this._redo.execute();
},
View
@@ -28,7 +28,7 @@ JS.Comparable = new JS.Module({
},
eq: function(other) {
- return this.compareTo(other) == 0;
+ return this.compareTo(other) === 0;
},
between: function(a, b) {
View
@@ -5,7 +5,7 @@ JS.Decorator = new JS.Class({
for (method in decoree.prototype) {
func = decoree.prototype[method];
- if (JS.isFn(func) && func != decoree) func = this.klass.delegate(method);
+ if (JS.isFn(func) && func !== decoree) func = this.klass.delegate(method);
delegators[method] = func;
}
View
@@ -53,10 +53,10 @@ JS.Enumerable = new JS.Module({
find: function(block, context) {
var needle = {}, K = needle;
this.forEach(function(item, i) {
- if (needle != K) return;
+ if (needle !== K) return;
needle = block.call(context || null, item, i) ? item : needle;
});
- return needle == K ? null : needle;
+ return needle === K ? null : needle;
},
inject: function(memo, block, context) {
@@ -85,7 +85,7 @@ JS.Enumerable = new JS.Module({
},
member: function(needle) {
- return this.any(function(item) { return item == needle; });
+ return this.any(function(item) { return item === needle; });
},
min: function(block, context) {
@@ -151,7 +151,7 @@ JS.Enumerable = new JS.Module({
block = arguments[n-2]; context = arguments[n-1];
}
util.forEach.call(arguments, function(arg) {
- if (arg == block || arg == context) return;
+ if (arg === block || arg === context) return;
if (arg.toArray) arg = arg.toArray();
if (arg instanceof Array) args.push(arg);
});
View
@@ -64,11 +64,11 @@ JS.LinkedList.Doubly = new JS.Class(JS.LinkedList, {
JS.LinkedList.insertTemplate = function(prev, next, pos) {
return function(node, newNode) {
- if (node.list != this) return;
+ if (node.list !== this) return;
newNode[prev] = node;
newNode[next] = node[next];
node[next] = (node[next][prev] = newNode);
- if (newNode[prev] == this[pos]) this[pos] = newNode;
+ if (newNode[prev] === this[pos]) this[pos] = newNode;
newNode.list = this;
this.length++;
};
@@ -90,12 +90,12 @@ JS.LinkedList.Doubly.Circular = new JS.Class(JS.LinkedList.Doubly, {
},
remove: function(removed) {
- if (removed.list != this || this.length == 0) return null;
+ if (removed.list !== this || this.length === 0) return null;
if (this.length > 1) {
removed.prev.next = removed.next;
removed.next.prev = removed.prev;
- if (removed == this.first) this.first = removed.next;
- if (removed == this.last) this.last = removed.prev;
+ if (removed === this.first) this.first = removed.next;
+ if (removed === this.last) this.last = removed.prev;
} else {
this.first = this.last = null;
}
View
@@ -23,7 +23,7 @@ JS.MethodChain.fire = function(queue, object) {
case 'function': property = method.func; break;
case 'object': object = method.func; continue loop; break;
}
- object = (typeof property == 'function')
+ object = (typeof property === 'function')
? property.apply(object, method.args)
: property;
}
@@ -66,12 +66,12 @@ JS.MethodChain.addMethods = function(object) {
var methods = [], property, i;
for (property in object)
- Number(property) != property && methods.push(property);
+ Number(property) !== property && methods.push(property);
if (object instanceof Array) {
i = object.length;
while (i--)
- typeof object[i] == 'string' && methods.push(object[i]);
+ typeof object[i] === 'string' && methods.push(object[i]);
}
i = methods.length;
while (i--) this.addMethod(methods[i]);
@@ -90,10 +90,10 @@ JS.ObjectMethods.include({
wait: function(time) {
var chain = new JS.MethodChain;
- typeof time == 'number' &&
+ typeof time === 'number' &&
setTimeout(chain.fire.bind(chain, this), time * 1000);
- this.forEach && typeof time == 'function' &&
+ this.forEach && typeof time === 'function' &&
this.forEach(function() {
setTimeout(chain.fire.bind(chain, arguments[0]), time.apply(this, arguments) * 1000);
});
@@ -104,8 +104,8 @@ JS.ObjectMethods.include({
_: function() {
var base = arguments[0], args = [], i, n;
for (i = 1, n = arguments.length; i < n; i++) args.push(arguments[i]);
- return (typeof base == 'object' && base) ||
- (typeof base == 'function' && base.apply(this, args)) ||
+ return (typeof base === 'object' && base) ||
+ (typeof base === 'function' && base.apply(this, args)) ||
this;
}
});
View
@@ -8,7 +8,7 @@ JS.Observable = new JS.Module({
context = context || null;
var i = this.countObservers();
while (i--) {
- if (this.__observers__[i].bk == observer && this.__observers__[i].cx == context) {
+ if (this.__observers__[i].bk === observer && this.__observers__[i].cx === context) {
this.__observers__.splice(i,1);
return;
}
View
@@ -6,17 +6,17 @@ JS.Package = new JS.Class({
},
addDependency: function(pkg) {
- if (typeof pkg == 'string') pkg = this.klass.getByName(pkg);
+ if (typeof pkg === 'string') pkg = this.klass.getByName(pkg);
if (!pkg) return;
- if (JS.indexOf(this._deps, pkg) == -1) this._deps.push(pkg);
+ if (JS.indexOf(this._deps, pkg) === -1) this._deps.push(pkg);
},
addName: function(name) {
if (!this.contains(name)) this._names.push(name);
},
contains: function(name) {
- return JS.indexOf(this._names, name) != -1;
+ return JS.indexOf(this._names, name) !== -1;
},
getObjects: function() {
@@ -33,14 +33,14 @@ JS.Package = new JS.Class({
if (deep !== false) {
while (n--) { if (!this._deps[n].isLoaded()) return false; }
}
- return this.getObjects().length == this._names.length;
+ return this.getObjects().length === this._names.length;
},
expand: function(list) {
var deps = list || [], i, n;
for (i = 0, n = this._deps.length; i < n; i++)
this._deps[i].expand(deps);
- if (JS.indexOf(deps, this) == -1) deps.push(this);
+ if (JS.indexOf(deps, this) === -1) deps.push(this);
return deps;
},
@@ -51,9 +51,9 @@ JS.Package = new JS.Class({
tag.src = this._path;
tag.onload = tag.onreadystatechange = function() {
if ( !tag.readyState ||
- tag.readyState == 'loaded' ||
- tag.readyState == 'complete' ||
- (tag.readyState == 4 && tag.status == 200)
+ tag.readyState === 'loaded' ||
+ tag.readyState === 'complete' ||
+ (tag.readyState === 4 && tag.status === 200)
) {
callback.call(scope || null);
tag = null;
@@ -93,7 +93,7 @@ JS.Package = new JS.Class({
},
load: function(list, callback, scope) {
- if (list.length == 0) return callback && callback.call(scope || null);
+ if (list.length === 0) return callback && callback.call(scope || null);
list.shift().injectScript(function() {
this.load(list, callback, scope);
}, this);
@@ -128,7 +128,7 @@ JS.Packages = function(declaration) {
require = function() {
var args = JS.array(arguments), requirements = [];
- while (typeof args[0] == 'string') requirements.push(JS.Package.getByName(args.shift()));
+ while (typeof args[0] === 'string') requirements.push(JS.Package.getByName(args.shift()));
requirements = JS.Package.expand(requirements);
JS.Package.load(requirements, args[0], args[1]);
};
View
@@ -9,7 +9,7 @@ JS.Proxy.Virtual = new JS.Class({
for (method in klass.prototype) {
func = klass.prototype[method];
- if (JS.isFn(func) && func != klass) func = this.klass.forward(method);
+ if (JS.isFn(func) && func !== klass) func = this.klass.forward(method);
delegators[method] = func;
}
View
@@ -59,7 +59,7 @@ JS.Set = new JS.Class({
},
contains: function(item) {
- return this._indexOf(item) != -1;
+ return this._indexOf(item) !== -1;
},
difference: function(other) {
@@ -78,7 +78,7 @@ JS.Set = new JS.Class({
},
equals: function(other) {
- if (this.length != other.length || !(other instanceof JS.Set)) return false;
+ if (this.length !== other.length || !(other instanceof JS.Set)) return false;
var i = this._members.length;
while (i--) {
if (!other.contains(this._members[i])) return false;
@@ -106,7 +106,7 @@ JS.Set = new JS.Class({
},
isEmpty: function() {
- return this._members.length == 0;
+ return this._members.length === 0;
},
isProperSubset: function(other) {
@@ -151,7 +151,7 @@ JS.Set = new JS.Class({
remove: function(item) {
var index = this._indexOf(item);
- if (index == -1) return;
+ if (index === -1) return;
this._members.splice(index, 1);
this.length = this.size = this._members.length;
},
@@ -225,7 +225,7 @@ JS.SortedSet = new JS.Class(JS.Set, {
_indexOf: function(item, insertionPoint) {
var items = this._members, n = items.length, i = 0, d = n;
- if (n == 0) return insertionPoint ? 0 : -1;
+ if (n === 0) return insertionPoint ? 0 : -1;
var compare = this.klass.compare, equal = this.klass.areEqual;
if (compare(item, items[0]) < 1) { d = 0; i = 0; }
@@ -240,7 +240,7 @@ JS.SortedSet = new JS.Class(JS.Set, {
// The pointer will end up at the start of any homogenous section. Step
// through the section until we find the needle or until the section ends.
while (items[i] && !equal(item, items[i]) &&
- compare(item, items[i]) == 0) i += 1;
+ compare(item, items[i]) === 0) i += 1;
var found = equal(item, items[i]);
return insertionPoint
Oops, something went wrong.

0 comments on commit 1d4766f

Please sign in to comment.