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 7f18d29287aad960fda58b29e3362c9323fc23db
Showing with 2 additions and 4 deletions.
  1. +2 −4 src/core.js
@@ -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

This comment has been minimized.

Copy link
Contributor

rkatic replied Aug 27, 2010

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

@ehynds

This comment has been minimized.

Copy link

ehynds replied Aug 27, 2010

@jdalton

This comment has been minimized.

Copy link
Member

jdalton replied Aug 27, 2010

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

This comment has been minimized.

Copy link
Contributor

rkatic replied Aug 27, 2010

@ehynds, @jdalton: Thx.

@steida

This comment has been minimized.

Copy link

steida replied Aug 27, 2010

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

Please sign in to comment.
You can’t perform that action at this time.