Replace all type converting string compares with ===, !==.

This commit is contained in:
Jürg Lehni 2011-04-28 13:23:17 +01:00
parent 115ef45464
commit 4d999d57e2
10 changed files with 24 additions and 24 deletions

6
lib/bootstrap.js vendored
View file

@ -18,7 +18,7 @@ var Base = this.Base = new function() {
proto = Object.prototype, proto = Object.prototype,
has = fix has = fix
? function(name) { ? function(name) {
return name != '__proto__' && this.hasOwnProperty(name); return name !== '__proto__' && this.hasOwnProperty(name);
} }
: proto.hasOwnProperty, : proto.hasOwnProperty,
toString = proto.toString, toString = proto.toString,
@ -77,7 +77,7 @@ var Base = this.Base = new function() {
function field(name, val, dontCheck, generics) { function field(name, val, dontCheck, generics) {
var val = val || (val = describe(src, name)) var val = val || (val = describe(src, name))
&& (val.get ? val : val.value), && (val.get ? val : val.value),
func = typeof val == 'function', res = val, func = typeof val === 'function', res = val,
prev = preserve || func prev = preserve || func
? (val && val.get ? name in dest : dest[name]) : null; ? (val && val.get ? name in dest : dest[name]) : null;
if (generics && func && (!preserve || !generics[name])) { if (generics && func && (!preserve || !generics[name])) {
@ -164,7 +164,7 @@ var Base = this.Base = new function() {
function iterator(iter) { function iterator(iter) {
return !iter return !iter
? function(val) { return val } ? function(val) { return val }
: typeof iter != 'function' : typeof iter !== 'function'
? function(val) { return val == iter } ? function(val) { return val == iter }
: iter; : iter;
} }

View file

@ -111,7 +111,7 @@ var Matrix = this.Matrix = Base.extend({
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform.
*/ */
scale: function(sx, sy /* | scale */, center) { 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 // sx is the single scale parameter, representing both sx and sy
// Read center first from argument 1, then set sy = sx (thus // Read center first from argument 1, then set sy = sx (thus
// modifing the content of argument 1!) // modifing the content of argument 1!)
@ -170,7 +170,7 @@ var Matrix = this.Matrix = Base.extend({
*/ */
shear: function(shx, shy, center) { shear: function(shx, shy, center) {
// See #scale() for explanation of this: // 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); center = Point.read(arguments, 1);
sy = sx; sy = sx;
} else { } else {

View file

@ -35,7 +35,7 @@ var Element = {
getScrollBounds: function() { getScrollBounds: function() {
var doc = document.getElementsByTagName( var doc = document.getElementsByTagName(
document.compatMode == 'CSS1Compat' ? 'html' : 'body')[0]; document.compatMode === 'CSS1Compat' ? 'html' : 'body')[0];
return Rectangle.create( return Rectangle.create(
window.pageXOffset || doc.scrollLeft, window.pageXOffset || doc.scrollLeft,
window.pageYOffset || doc.scrollTop, window.pageYOffset || doc.scrollTop,

View file

@ -62,7 +62,7 @@ var Color = this.Color = Base.extend(new function() {
initialize: function(arg) { initialize: function(arg) {
var isArray = Array.isArray(arg); var isArray = Array.isArray(arg);
if (typeof arg == 'object' && !isArray) { if (typeof arg === 'object' && !isArray) {
if (!this._colorType) { if (!this._colorType) {
// Called on the abstract Color class. Guess color type // Called on the abstract Color class. Guess color type
// from arg // from arg
@ -83,7 +83,7 @@ var Color = this.Color = Base.extend(new function() {
? color.convert(this._colorType) ? color.convert(this._colorType)
: color; : color;
} }
} else if (typeof arg == 'string') { } else if (typeof arg === 'string') {
var rgbColor = arg.match(/^#[0-9a-f]{3,6}$/i) var rgbColor = arg.match(/^#[0-9a-f]{3,6}$/i)
? hexToRGBColor(arg) ? hexToRGBColor(arg)
: nameToRGBColor(arg); : nameToRGBColor(arg);
@ -112,7 +112,7 @@ var Color = this.Color = Base.extend(new function() {
? value ? value
// TODO: Is this correct? // TODO: Is this correct?
// Shouldn't alpha be set to -1? // Shouldn't alpha be set to -1?
: name == 'alpha' ? 1 : null; : name === 'alpha' ? 1 : null;
}, this); }, this);
} }
} }
@ -177,7 +177,7 @@ var Color = this.Color = Base.extend(new function() {
for (var i = 0, l = this._components.length; i < l; i++) { for (var i = 0, l = this._components.length; i < l; i++) {
var component = this._components[i]; var component = this._components[i];
var value = this['_' + component]; var value = this['_' + component];
if (component == 'alpha' && value == null) if (component === 'alpha' && value == null)
value = 1; value = 1;
string += (i > 0 ? ', ' : '') + component + ': ' + value; string += (i > 0 ? ', ' : '') + component + ': ' + value;
} }
@ -186,7 +186,7 @@ var Color = this.Color = Base.extend(new function() {
toCssString: function() { toCssString: function() {
if (!this._cssString) { if (!this._cssString) {
var color = this._colorType == 'rgb' var color = this._colorType === 'rgb'
? this ? this
: this.convert('rgb'); : this.convert('rgb');
var alpha = color.getAlpha(); var alpha = color.getAlpha();

View file

@ -66,7 +66,7 @@ var GradientColor = this.GradientColor = Color.extend({
getCanvasStyle: function(ctx) { getCanvasStyle: function(ctx) {
var gradient; var gradient;
if (this.gradient.type == 'linear') { if (this.gradient.type === 'linear') {
gradient = ctx.createLinearGradient(this._origin.x, this._origin.y, gradient = ctx.createLinearGradient(this._origin.x, this._origin.y,
this.destination.x, this.destination.y); this.destination.x, this.destination.y);
} else { } else {

View file

@ -613,7 +613,7 @@ var Item = this.Item = Base.extend({
*/ */
scale: function(sx, sy /* | scale */, center) { scale: function(sx, sy /* | scale */, center) {
// See Matrix#scale for explanation of this: // See Matrix#scale for explanation of this:
if (arguments.length < 2 || typeof sy == 'object') { if (arguments.length < 2 || typeof sy === 'object') {
center = sy; center = sy;
sy = sx; sy = sx;
} }
@ -646,7 +646,7 @@ var Item = this.Item = Base.extend({
shear: function(shx, shy, center) { shear: function(shx, shy, center) {
// TODO: Add support for center back to Scriptographer too! // TODO: Add support for center back to Scriptographer too!
// See Matrix#scale for explanation of this: // See Matrix#scale for explanation of this:
if (arguments.length < 2 || typeof sy == 'object') { if (arguments.length < 2 || typeof sy === 'object') {
center = shy; center = shy;
shy = shx; shy = shx;
} }
@ -766,7 +766,7 @@ var Item = this.Item = Base.extend({
// If the item has a blendMode, use BlendMode#process to // If the item has a blendMode, use BlendMode#process to
// composite its canvas on the parentCanvas. // composite its canvas on the parentCanvas.
if (item.blendMode != 'normal') { if (item.blendMode !== 'normal') {
// The pixel offset of the temporary canvas to the parent // The pixel offset of the temporary canvas to the parent
// canvas. // canvas.
var pixelOffset = itemOffset.subtract(param.offset); var pixelOffset = itemOffset.subtract(param.offset);
@ -922,7 +922,7 @@ var Item = this.Item = Base.extend({
var hash = {}; var hash = {};
hash[handler] = function(event) { hash[handler] = function(event) {
// Always clear the drag set on mouse-up // Always clear the drag set on mouse-up
if (name == 'up') if (name === 'up')
sets.drag = {}; sets.drag = {};
removeAll(sets[name]); removeAll(sets[name]);
sets[name] = {}; sets[name] = {};
@ -950,7 +950,7 @@ var Item = this.Item = Base.extend({
sets[name][this.getId()] = this; sets[name][this.getId()] = this;
// Since the drag set gets cleared in up, we need to make // Since the drag set gets cleared in up, we need to make
// sure it's installed too // sure it's installed too
if (name == 'drag') if (name === 'drag')
installHandler('up'); installHandler('up');
installHandler(name); installHandler(name);
} }

View file

@ -25,7 +25,7 @@ var Raster = this.Raster = Item.extend({
this.setCanvas(object); this.setCanvas(object);
} else { } else {
// If it's a string, get the element with this id first. // If it's a string, get the element with this id first.
if (typeof object == 'string') if (typeof object === 'string')
object = document.getElementById(object); object = document.getElementById(object);
this.setImage(object); this.setImage(object);
} }

View file

@ -102,7 +102,7 @@ if (window.tests) {
for (var i = 0; i < sources.length; i++) { for (var i = 0; i < sources.length; i++) {
document.write('<script type="text/javascript" src="' + (window.root || '') document.write('<script type="text/javascript" src="' + (window.root || '')
+ sources[i] + '"></script>'); + sources[i] + '"></script>');
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 // Activate paper.debug for code loaded through load.js, as we're in
// development mode. // development mode.
document.write('<script type="text/javascript">' document.write('<script type="text/javascript">'

View file

@ -25,7 +25,7 @@ var Path = this.Path = PathItem.extend({
// If it is an array, it can also be a description of a point, so // If it is an array, it can also be a description of a point, so
// check its first entry for object as well // check its first entry for object as well
this.setSegments(!segments || !Array.isArray(segments) this.setSegments(!segments || !Array.isArray(segments)
|| typeof segments[0] != 'object' ? arguments : segments); || typeof segments[0] !== 'object' ? arguments : segments);
}, },
/** /**
@ -674,7 +674,7 @@ var Path = this.Path = PathItem.extend({
// Get the start point: // Get the start point:
var current = getCurrentSegment(this), var current = getCurrentSegment(this),
through; through;
if (arguments[1] && typeof arguments[1] != 'boolean') { if (arguments[1] && typeof arguments[1] !== 'boolean') {
through = Point.read(arguments, 0, 1); through = Point.read(arguments, 0, 1);
to = Point.read(arguments, 1, 1); to = Point.read(arguments, 1, 1);
} else { } else {
@ -987,7 +987,7 @@ var Path = this.Path = PathItem.extend({
handleOut = segment.getHandleOutIfSet(); handleOut = segment.getHandleOutIfSet();
// When both handles are set in a segment, the join setting is // When both handles are set in a segment, the join setting is
// ignored and round is always used. // ignored and round is always used.
if (join == 'round' || handleIn && handleOut) { if (join === 'round' || handleIn && handleOut) {
bounds = bounds.unite(joinBounds.setCenter(matrix bounds = bounds.unite(joinBounds.setCenter(matrix
? matrix.transform(segment._point) : segment._point)); ? matrix.transform(segment._point) : segment._point));
} else { } else {
@ -1033,7 +1033,7 @@ var Path = this.Path = PathItem.extend({
normal = curve.getNormal(t).normalize(radius); normal = curve.getNormal(t).normalize(radius);
// For square caps, we need to step away from point in the // For square caps, we need to step away from point in the
// direction of the tangent, which is the rotated normal // direction of the tangent, which is the rotated normal
if (cap == 'square') if (cap === 'square')
point = point.add(normal.y, -normal.x); point = point.add(normal.y, -normal.x);
add(point.add(normal)); add(point.add(normal));
add(point.subtract(normal)); add(point.subtract(normal));

View file

@ -29,7 +29,7 @@ var Key = new function() {
Event.add(document, Base.each(['keyDown', 'keyUp'], function(type) { Event.add(document, Base.each(['keyDown', 'keyUp'], function(type) {
var toolHandler = 'on' + Base.capitalize(type), var toolHandler = 'on' + Base.capitalize(type),
keyDown = type == 'keyDown'; keyDown = type === 'keyDown';
this[type.toLowerCase()] = function(event) { this[type.toLowerCase()] = function(event) {
var code = event.which || event.keyCode, var code = event.which || event.keyCode,
key = keys[code] || String.fromCharCode(code).toLowerCase(); key = keys[code] || String.fromCharCode(code).toLowerCase();