Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Land some additional tweaks related to running through JSLint.
  • Loading branch information
jeresig committed Mar 1, 2010
1 parent fc08d0e commit a4043cd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ajax.js
Expand Up @@ -2,7 +2,7 @@ var jsc = now(),
rscript = /<script(.|\s)*?\/script>/gi,
rselectTextarea = /select|textarea/i,
rinput = /color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i,
jsre = /=\?(&|$)/,
jsre = /\=\?(&|$)/,
rquery = /\?/,
rts = /(\?|&)_=.*?(&|$)/,
rurl = /^(\w+:)?\/\/([^\/?#]+)/,
Expand Down
12 changes: 6 additions & 6 deletions src/core.js
Expand Up @@ -49,7 +49,7 @@ var jQuery = function( selector, context ) {

// Save a reference to some core methods
toString = Object.prototype.toString,
hasOwnProperty = Object.prototype.hasOwnProperty,
hasOwn = Object.prototype.hasOwnProperty,
push = Array.prototype.push,
slice = Array.prototype.slice,
indexOf = Array.prototype.indexOf;
Expand Down Expand Up @@ -450,9 +450,9 @@ jQuery.extend({
}

// Not own constructor property must be Object
if ( obj.constructor
&& !hasOwnProperty.call(obj, "constructor")
&& !hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf") ) {
if ( obj.constructor &&
!hasOwn.call(obj, "constructor") &&
!hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
return false;
}

Expand All @@ -462,7 +462,7 @@ jQuery.extend({
var key;
for ( key in obj ) {}

return key === undefined || hasOwnProperty.call( obj, key );
return key === undefined || hasOwn.call( obj, key );
},

isEmptyObject: function( obj ) {
Expand Down Expand Up @@ -803,5 +803,5 @@ function access( elems, key, value, exec, fn, pass ) {
}

function now() {
return (new Date).getTime();
return (new Date()).getTime();
}
2 changes: 1 addition & 1 deletion src/event.js
Expand Up @@ -187,7 +187,7 @@ jQuery.event = {
type = namespaces.shift();

namespace = new RegExp("(^|\\.)" +
jQuery.map( namespaces.slice(0).sort(), fcleanup ).join("\\.(?:.*\\.)?") + "(\\.|$)")
jQuery.map( namespaces.slice(0).sort(), fcleanup ).join("\\.(?:.*\\.)?") + "(\\.|$)");
}

eventType = events[ type ];
Expand Down
2 changes: 1 addition & 1 deletion src/manipulation.js
Expand Up @@ -205,7 +205,7 @@ jQuery.fn.extend({

return jQuery.clean([html.replace(rinlinejQuery, "")
// Handle the case in IE 8 where action=/test/> self-closes a tag
.replace(/=([^="'>\s]+\/)>/g, '="$1">')
.replace(/\=([^="'>\s]+\/)>/g, '="$1">')
.replace(rleadingWhitespace, "")], ownerDocument)[0];
} else {
return this.cloneNode(true);
Expand Down
3 changes: 1 addition & 2 deletions src/traversing.js
@@ -1,8 +1,7 @@
var runtil = /Until$/,
rparentsprev = /^(?:parents|prevUntil|prevAll)/,
// Note: This RegExp should be improved, or likely pulled from Sizzle
rmultiselector = /,/,
slice = Array.prototype.slice;
rmultiselector = /,/;

// Implement the identical functionality for filter and not
var winnow = function( elements, qualifier, keep ) {
Expand Down

9 comments on commit a4043cd

@padolsey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In reference to 806, what's wrong with +new Date()?

@jeresig
Copy link
Member Author

@jeresig jeresig commented on a4043cd Mar 2, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@james: Nothing in particular (in that it works) but I've balked against it in the past because it's particularly "magical" and not always obvious what it's doing to someone who may be reading the source - whereas (new Date()).getTime() is very explicit and very obvious as to what the result is.

@padolsey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. I'm surprised closure compiler doesn't switch new Date().getTime() for +new Date...

@jdalton
Copy link
Member

@jdalton jdalton commented on a4043cd Mar 2, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing magical about it. ECMA 5th Ed. Page 169, Section 15.9.3.1 [[PrimitiveValue]] makes it pretty clear. (new Date).valueOf(); would also do :P

@jeresig
Copy link
Member Author

@jeresig jeresig commented on a4043cd Mar 2, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdalton: To someone that reads specifications for fun, of course there's "Nothing magical about it." - but it's undeniable that it's much more obtuse than just doing a straight (new Date()).getTime(); or (new Date()).valueOf();.

@jdalton
Copy link
Member

@jdalton jdalton commented on a4043cd Mar 2, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, I hear @kangax is getting a tramp stamp that reads "strict";

@jdalton
Copy link
Member

@jdalton jdalton commented on a4043cd Mar 2, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*erm "use strict";, humor fail :D

@cowboy
Copy link
Member

@cowboy cowboy commented on a4043cd Mar 2, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use +new Date() and then include a comment. You know, one of those new-fangled thingamawhatsits often included in source code just like this that explains to the uneducated developer what that particular bit of magic does?

@yfeldblum
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are verboten.

On a serious note, it's a popular idea that code should be clear - that if a piece of code needs comments to explain what it does, then that piece of code should be rewritten no longer to need comments.

Appropriate optimizations are exceptions to this rule, as are such things as high-level descriptions of algorithms and data structures, high-level descriptions of design and architecture, examples of how to invoke the code, key assumptions and contexts, etc.

Please sign in to comment.