Skip to content
Permalink
Browse files
Simplify the logic in $.type, thanks to jdalton for the suggesiton in 5…
  • Loading branch information
jeresig committed Aug 27, 2010
1 parent 5d2be7e commit 7f18d29
Showing 1 changed file with 2 additions and 4 deletions.
@@ -446,10 +446,8 @@ jQuery.extend({
},

type: function( obj ) {
return obj === null ?
"null" :
obj === undefined ?
"undefined" :
return obj == null ?
String( obj ) :
toString.call(obj).slice(8, -1).toLowerCase();
},

5 comments on commit 7f18d29

@rkatic
Copy link
Contributor

@rkatic rkatic commented on 7f18d29 Aug 27, 2010

Choose a reason for hiding this comment

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

Ok. Is String( obj ) safer or faster then "" + obj?

@ehynds
Copy link

@ehynds ehynds commented on 7f18d29 Aug 27, 2010

Choose a reason for hiding this comment

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

@jdalton
Copy link
Member

Choose a reason for hiding this comment

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

They are equivalent in speed (both hundreds of thousands or millions each and fluctuate back n forth between retests).
It is a coding style preference. Using String() shows intent more than "" + obj is all.

@rkatic
Copy link
Contributor

@rkatic rkatic commented on 7f18d29 Aug 27, 2010

Choose a reason for hiding this comment

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

@ehynds, @jdalton: Thx.

@steida
Copy link

@steida steida commented on 7f18d29 Aug 27, 2010

Choose a reason for hiding this comment

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

my type suggestion http://gist.github.com/204554

Please sign in to comment.