From 4d999d57e2e1206210963ecad9d416b95dd9e2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 28 Apr 2011 13:23:17 +0100 Subject: [PATCH] Replace all type converting string compares with ===, !==. --- lib/bootstrap.js | 6 +++--- src/basic/Matrix.js | 4 ++-- src/browser/Element.js | 2 +- src/color/Color.js | 10 +++++----- src/color/GradientColor.js | 2 +- src/item/Item.js | 10 +++++----- src/item/Raster.js | 2 +- src/load.js | 2 +- src/path/Path.js | 8 ++++---- src/ui/Key.js | 2 +- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/bootstrap.js b/lib/bootstrap.js index c77e7ade..f1632e5c 100644 --- a/lib/bootstrap.js +++ b/lib/bootstrap.js @@ -18,7 +18,7 @@ var Base = this.Base = new function() { proto = Object.prototype, has = fix ? function(name) { - return name != '__proto__' && this.hasOwnProperty(name); + return name !== '__proto__' && this.hasOwnProperty(name); } : proto.hasOwnProperty, toString = proto.toString, @@ -77,7 +77,7 @@ var Base = this.Base = new function() { function field(name, val, dontCheck, generics) { var val = val || (val = describe(src, name)) && (val.get ? val : val.value), - func = typeof val == 'function', res = val, + func = typeof val === 'function', res = val, prev = preserve || func ? (val && val.get ? name in dest : dest[name]) : null; if (generics && func && (!preserve || !generics[name])) { @@ -164,7 +164,7 @@ var Base = this.Base = new function() { function iterator(iter) { return !iter ? function(val) { return val } - : typeof iter != 'function' + : typeof iter !== 'function' ? function(val) { return val == iter } : iter; } diff --git a/src/basic/Matrix.js b/src/basic/Matrix.js index d1b18982..89e4e13b 100644 --- a/src/basic/Matrix.js +++ b/src/basic/Matrix.js @@ -111,7 +111,7 @@ var Matrix = this.Matrix = Base.extend({ * @return {Matrix} This affine transform. */ scale: function(sx, sy /* | scale */, center) { - if (arguments.length < 2 || typeof sy == 'object') { + if (arguments.length < 2 || typeof sy === 'object') { // sx is the single scale parameter, representing both sx and sy // Read center first from argument 1, then set sy = sx (thus // modifing the content of argument 1!) @@ -170,7 +170,7 @@ var Matrix = this.Matrix = Base.extend({ */ shear: function(shx, shy, center) { // See #scale() for explanation of this: - if (arguments.length < 2 || typeof shy == 'object') { + if (arguments.length < 2 || typeof shy === 'object') { center = Point.read(arguments, 1); sy = sx; } else { diff --git a/src/browser/Element.js b/src/browser/Element.js index d15fa2a8..dcc42f5a 100644 --- a/src/browser/Element.js +++ b/src/browser/Element.js @@ -35,7 +35,7 @@ var Element = { getScrollBounds: function() { var doc = document.getElementsByTagName( - document.compatMode == 'CSS1Compat' ? 'html' : 'body')[0]; + document.compatMode === 'CSS1Compat' ? 'html' : 'body')[0]; return Rectangle.create( window.pageXOffset || doc.scrollLeft, window.pageYOffset || doc.scrollTop, diff --git a/src/color/Color.js b/src/color/Color.js index 7cb5931f..b8b53d1b 100644 --- a/src/color/Color.js +++ b/src/color/Color.js @@ -62,7 +62,7 @@ var Color = this.Color = Base.extend(new function() { initialize: function(arg) { var isArray = Array.isArray(arg); - if (typeof arg == 'object' && !isArray) { + if (typeof arg === 'object' && !isArray) { if (!this._colorType) { // Called on the abstract Color class. Guess color type // from arg @@ -83,7 +83,7 @@ var Color = this.Color = Base.extend(new function() { ? color.convert(this._colorType) : color; } - } else if (typeof arg == 'string') { + } else if (typeof arg === 'string') { var rgbColor = arg.match(/^#[0-9a-f]{3,6}$/i) ? hexToRGBColor(arg) : nameToRGBColor(arg); @@ -112,7 +112,7 @@ var Color = this.Color = Base.extend(new function() { ? value // TODO: Is this correct? // Shouldn't alpha be set to -1? - : name == 'alpha' ? 1 : null; + : name === 'alpha' ? 1 : null; }, this); } } @@ -177,7 +177,7 @@ var Color = this.Color = Base.extend(new function() { for (var i = 0, l = this._components.length; i < l; i++) { var component = this._components[i]; var value = this['_' + component]; - if (component == 'alpha' && value == null) + if (component === 'alpha' && value == null) value = 1; string += (i > 0 ? ', ' : '') + component + ': ' + value; } @@ -186,7 +186,7 @@ var Color = this.Color = Base.extend(new function() { toCssString: function() { if (!this._cssString) { - var color = this._colorType == 'rgb' + var color = this._colorType === 'rgb' ? this : this.convert('rgb'); var alpha = color.getAlpha(); diff --git a/src/color/GradientColor.js b/src/color/GradientColor.js index 11486eab..b75c3c84 100644 --- a/src/color/GradientColor.js +++ b/src/color/GradientColor.js @@ -66,7 +66,7 @@ var GradientColor = this.GradientColor = Color.extend({ getCanvasStyle: function(ctx) { var gradient; - if (this.gradient.type == 'linear') { + if (this.gradient.type === 'linear') { gradient = ctx.createLinearGradient(this._origin.x, this._origin.y, this.destination.x, this.destination.y); } else { diff --git a/src/item/Item.js b/src/item/Item.js index a3054248..5ccadcee 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -613,7 +613,7 @@ var Item = this.Item = Base.extend({ */ scale: function(sx, sy /* | scale */, center) { // See Matrix#scale for explanation of this: - if (arguments.length < 2 || typeof sy == 'object') { + if (arguments.length < 2 || typeof sy === 'object') { center = sy; sy = sx; } @@ -646,7 +646,7 @@ var Item = this.Item = Base.extend({ shear: function(shx, shy, center) { // TODO: Add support for center back to Scriptographer too! // See Matrix#scale for explanation of this: - if (arguments.length < 2 || typeof sy == 'object') { + if (arguments.length < 2 || typeof sy === 'object') { center = shy; shy = shx; } @@ -766,7 +766,7 @@ var Item = this.Item = Base.extend({ // If the item has a blendMode, use BlendMode#process to // composite its canvas on the parentCanvas. - if (item.blendMode != 'normal') { + if (item.blendMode !== 'normal') { // The pixel offset of the temporary canvas to the parent // canvas. var pixelOffset = itemOffset.subtract(param.offset); @@ -922,7 +922,7 @@ var Item = this.Item = Base.extend({ var hash = {}; hash[handler] = function(event) { // Always clear the drag set on mouse-up - if (name == 'up') + if (name === 'up') sets.drag = {}; removeAll(sets[name]); sets[name] = {}; @@ -950,7 +950,7 @@ var Item = this.Item = Base.extend({ sets[name][this.getId()] = this; // Since the drag set gets cleared in up, we need to make // sure it's installed too - if (name == 'drag') + if (name === 'drag') installHandler('up'); installHandler(name); } diff --git a/src/item/Raster.js b/src/item/Raster.js index c85b4ee9..f6625d92 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -25,7 +25,7 @@ var Raster = this.Raster = Item.extend({ this.setCanvas(object); } else { // If it's a string, get the element with this id first. - if (typeof object == 'string') + if (typeof object === 'string') object = document.getElementById(object); this.setImage(object); } diff --git a/src/load.js b/src/load.js index c7850c2b..c9e604a6 100644 --- a/src/load.js +++ b/src/load.js @@ -102,7 +102,7 @@ if (window.tests) { for (var i = 0; i < sources.length; i++) { document.write(''); - if (sources[i] == 'src/paper.js') { + if (sources[i] === 'src/paper.js') { // Activate paper.debug for code loaded through load.js, as we're in // development mode. document.write('