[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-08-03 Thread DBJDBJ


There are two main points here: terminology and reliability.
http://dbj.org/dbj/?p=270
(sorry for a blog plug )

typeof( window.alert )  === 'object' is going head-on towards browser
(+OS) differences so, same as ECMA comitee, I have no resources to
solve that one ...

--DBJ

On Aug 1, 3:16 pm, Andrea Giammarchi andrea.giammar...@gmail.com
wrote:
 come on it was quoted as a metaphor ... what you have done makes sense but
 if the point is reliability it does not in any case with IE so let's speed
 up a common function, no?

 On Sat, Aug 1, 2009 at 2:17 PM, DBJDBJ dbj...@gmail.com wrote:

  ... DBJ 'mess' ...  ?

  One espresso to many , Andrea :-)  ?

  PS:  I think that top.alert() is object in IE because they can't
  think of DOM as a exclusive domain of javascript. There is this thing
  called vbscript they have to make work inside IE, as well ... but ..
  let's not go there ;o)

  On Jul 27, 5:43 pm, Andrea Giammarchi andrea.giammar...@gmail.com
  wrote:
   Yes Daniel ... ( sorry I had another ticket open and I read Ariel ... )

   On Mon, Jul 27, 2009 at 5:43 PM, Andrea Giammarchi 

   andrea.giammar...@gmail.com wrote:
Yes Ariel, I was talking about user defined stuff and obviously typeof
unknown breaks the rule as well but this is not the case, is it?

If toString.call(obj) is not reliable cause it could return [object
  Object]
DBJ mess is not reliable as well because passed variable could not
  produce
what he is expecting, starting from document.getElementById which is
  object
and not function in IE, got the point?

At least you told me why there is a call rather than an instanceof but
  what
about this for IE DOM functions?

return !!obj  typeof obj.toString === undefined 
/^\s*\bfunction\b/.test(obj);

it works fine to me in every IE (other browsers will be filtered by
  first
feature test)

Regards

On Mon, Jul 27, 2009 at 5:29 PM, Daniel Friesen 
  nadir.seen.f...@gmail.com
 wrote:

typeof fn === 'function'; // Some things like
document.createElement('object'); return wonky results
fn instanceof Function; // Breaks across iFrames
toString.call(fn) === [object Function]; // Works the same across
iFrames and returns more reliable results

~Daniel Friesen (Dantman, Nadir-Seen-Fire) [
 http://daniel.friesen.name]

Andrea Giammarchi wrote:
 About isFunction

 I lost the point where toString.call(obj) === [object Function]
  was
 introduced instead of obj instanceof function

 I understand differences in IE so I wonder if two distinct callbacks
 could solve the odyssey:

     isFunction: function( obj ) {
         return obj instanceof Function;
     },

     isDOMFunction: toString.call(window.alert) === [object
  Function] ?
         function( obj ) {
             return toString.call(obj) === [object Function];
         }:
         // IE only and only until standard native function manifest
         function( obj ){
             return !!obj  typeof obj.toString === undefined 
 /^\s*\bfunction\b/.test(obj);
         }
     ,

 In this way we could consider that in every browser, and when
 call/apply are supported, isFunction(fn) will guarantee call/apply
 while a DOMFunction could require a try catch or a different
  behavior
 for IE

 switch(true){
     case $.isFunction(fn): return fn.call(what, ever);
     case $.isDOMFunction(fn): what.push.call(what,
  toArray(fn(ever)));
 return what;
     default: throw new Error(what tf?);
 }

 ... or maybe not?
 Regards

 On Sun, Jul 26, 2009 at 4:09 PM, Andrea Giammarchi
 andrea.giammar...@gmail.com mailto:andrea.giammar...@gmail.com
wrote:

     I usually encapsulate toString from Object.prototype and if
     somebody breaks the rule it means we cannot trust anything
     included typeof. So, in few words, nobody has intersts into
  break
     this rule, imho.

     On Jul 26, 2009 8:07 AM, DBJDBJ dbj...@gmail.com
     mailto:dbj...@gmail.com wrote:

     Also, IMHO this yields high level of encapsulation of an
  important
     mechanism.
     Which is a good thing.
     And it is a fraction of a micro second slower then

     Object.prototype.toString.call(x) === [object Object]

     but it is more compact ...

     In any case we are entering the subjective judgement phase, so
  I
     think
     we should stop here and leave it to jQuery team to use this or
not...

     --DBJ On Jul 26, 12:09 am, Andrea Giammarchi
     andrea.giammar...@gmail.com
     mailto:andrea.giammar...@gmail.com wrote:

      I miss the point about regexp usage ... please tell me the
     difference (in a  real scenario) betwe...

      On Sat, Jul 25, 2009 at 1:38 PM, DBJDBJ dbj...@gmail.com
     mailto:dbj...@gmail.com wrote:This indeed woks :
 functi...

[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-08-03 Thread Andrea Giammarchi
As summary

return !!obj  typeof obj.toString === undefined 
/^\s*\bfunction\b/.test(obj);

with a given IE function, it should not fail. Other browsers can use the
good old [object Function] trick.

On Mon, Aug 3, 2009 at 11:38 AM, Andrea Giammarchi 
andrea.giammar...@gmail.com wrote:

 I solved it already, have you tried my snippet to understand native IE
 functions?

 Native IE functions have these features
  - they are not instanteof Function
  - they are not instanceof Object
  - accordingly, they have not a toString method, decompilation is in this
 case safe enough
  - you cannot call them via Function callbacks ( function expected, lol )

 Regards


 On Mon, Aug 3, 2009 at 10:57 AM, DBJDBJ dbj...@gmail.com wrote:



 There are two main points here: terminology and reliability.
 http://dbj.org/dbj/?p=270
 (sorry for a blog plug )

 typeof( window.alert )  === 'object' is going head-on towards browser
 (+OS) differences so, same as ECMA comitee, I have no resources to
 solve that one ...

 --DBJ

 On Aug 1, 3:16 pm, Andrea Giammarchi andrea.giammar...@gmail.com
 wrote:
  come on it was quoted as a metaphor ... what you have done makes sense
 but
  if the point is reliability it does not in any case with IE so let's
 speed
  up a common function, no?
 
  On Sat, Aug 1, 2009 at 2:17 PM, DBJDBJ dbj...@gmail.com wrote:
 
   ... DBJ 'mess' ...  ?
 
   One espresso to many , Andrea :-)  ?
 
   PS:  I think that top.alert() is object in IE because they can't
   think of DOM as a exclusive domain of javascript. There is this thing
   called vbscript they have to make work inside IE, as well ... but ..
   let's not go there ;o)
 
   On Jul 27, 5:43 pm, Andrea Giammarchi andrea.giammar...@gmail.com
   wrote:
Yes Daniel ... ( sorry I had another ticket open and I read Ariel
 ... )
 
On Mon, Jul 27, 2009 at 5:43 PM, Andrea Giammarchi 
 
andrea.giammar...@gmail.com wrote:
 Yes Ariel, I was talking about user defined stuff and obviously
 typeof
 unknown breaks the rule as well but this is not the case, is it?
 
 If toString.call(obj) is not reliable cause it could return
 [object
   Object]
 DBJ mess is not reliable as well because passed variable could
 not
   produce
 what he is expecting, starting from document.getElementById which
 is
   object
 and not function in IE, got the point?
 
 At least you told me why there is a call rather than an instanceof
 but
   what
 about this for IE DOM functions?
 
 return !!obj  typeof obj.toString === undefined 
 /^\s*\bfunction\b/.test(obj);
 
 it works fine to me in every IE (other browsers will be filtered
 by
   first
 feature test)
 
 Regards
 
 On Mon, Jul 27, 2009 at 5:29 PM, Daniel Friesen 
   nadir.seen.f...@gmail.com
  wrote:
 
 typeof fn === 'function'; // Some things like
 document.createElement('object'); return wonky results
 fn instanceof Function; // Breaks across iFrames
 toString.call(fn) === [object Function]; // Works the same
 across
 iFrames and returns more reliable results
 
 ~Daniel Friesen (Dantman, Nadir-Seen-Fire) [
  http://daniel.friesen.name]
 
 Andrea Giammarchi wrote:
  About isFunction
 
  I lost the point where toString.call(obj) === [object
 Function]
   was
  introduced instead of obj instanceof function
 
  I understand differences in IE so I wonder if two distinct
 callbacks
  could solve the odyssey:
 
  isFunction: function( obj ) {
  return obj instanceof Function;
  },
 
  isDOMFunction: toString.call(window.alert) === [object
   Function] ?
  function( obj ) {
  return toString.call(obj) === [object Function];
  }:
  // IE only and only until standard native function
 manifest
  function( obj ){
  return !!obj  typeof obj.toString === undefined
 
  /^\s*\bfunction\b/.test(obj);
  }
  ,
 
  In this way we could consider that in every browser, and when
  call/apply are supported, isFunction(fn) will guarantee
 call/apply
  while a DOMFunction could require a try catch or a different
   behavior
  for IE
 
  switch(true){
  case $.isFunction(fn): return fn.call(what, ever);
  case $.isDOMFunction(fn): what.push.call(what,
   toArray(fn(ever)));
  return what;
  default: throw new Error(what tf?);
  }
 
  ... or maybe not?
  Regards
 
  On Sun, Jul 26, 2009 at 4:09 PM, Andrea Giammarchi
  andrea.giammar...@gmail.com mailto:
 andrea.giammar...@gmail.com
 wrote:
 
  I usually encapsulate toString from Object.prototype and if
  somebody breaks the rule it means we cannot trust anything
  included typeof. So, in few words, nobody has intersts into
   break
  this rule, imho.
 
  On Jul 26, 2009 8:07 AM, DBJDBJ dbj...@gmail.com
  mailto:dbj...@gmail.com wrote:
 
   

[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-27 Thread Andrea Giammarchi
About isFunction

I lost the point where toString.call(obj) === [object Function] was
introduced instead of obj instanceof function

I understand differences in IE so I wonder if two distinct callbacks could
solve the odyssey:

isFunction: function( obj ) {
return obj instanceof Function;
},

isDOMFunction: toString.call(window.alert) === [object Function] ?
function( obj ) {
return toString.call(obj) === [object Function];
}:
// IE only and only until standard native function manifest
function( obj ){
return !!obj  typeof obj.toString === undefined 
/^\s*\bfunction\b/.test(obj);
}
,

In this way we could consider that in every browser, and when call/apply are
supported, isFunction(fn) will guarantee call/apply while a DOMFunction
could require a try catch or a different behavior for IE

switch(true){
case $.isFunction(fn): return fn.call(what, ever);
case $.isDOMFunction(fn): what.push.call(what, toArray(fn(ever)));
return what;
default: throw new Error(what tf?);
}

... or maybe not?
Regards



On Sun, Jul 26, 2009 at 4:09 PM, Andrea Giammarchi 
andrea.giammar...@gmail.com wrote:

 I usually encapsulate toString from Object.prototype and if somebody breaks
 the rule it means we cannot trust anything included typeof. So, in few
 words, nobody has intersts into break this rule, imho.

 On Jul 26, 2009 8:07 AM, DBJDBJ dbj...@gmail.com wrote:


 Also, IMHO this yields high level of encapsulation of an important
 mechanism.
 Which is a good thing.
 And it is a fraction of a micro second slower then

 Object.prototype.toString.call(x) === [object Object]
 but it is more compact ...

 In any case we are entering the subjective judgement phase, so I think
 we should stop here and leave it to jQuery team to use this or not...

 --DBJ On Jul 26, 12:09 am, Andrea Giammarchi andrea.giammar...@gmail.com
 wrote:

  I miss the point about regexp usage ... please tell me the difference (in
 a  real scenario) betwe...

  On Sat, Jul 25, 2009 at 1:38 PM, DBJDBJ dbj...@gmail.com wrote:   
 This indeed woks :  functi...



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---



[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-27 Thread Daniel Friesen

typeof fn === 'function'; // Some things like 
document.createElement('object'); return wonky results
fn instanceof Function; // Breaks across iFrames
toString.call(fn) === [object Function]; // Works the same across 
iFrames and returns more reliable results

~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]

Andrea Giammarchi wrote:
 About isFunction

 I lost the point where toString.call(obj) === [object Function] was 
 introduced instead of obj instanceof function

 I understand differences in IE so I wonder if two distinct callbacks 
 could solve the odyssey:

 isFunction: function( obj ) {
 return obj instanceof Function;
 },

 isDOMFunction: toString.call(window.alert) === [object Function] ?
 function( obj ) {
 return toString.call(obj) === [object Function];
 }:
 // IE only and only until standard native function manifest
 function( obj ){
 return !!obj  typeof obj.toString === undefined  
 /^\s*\bfunction\b/.test(obj);
 }
 ,

 In this way we could consider that in every browser, and when 
 call/apply are supported, isFunction(fn) will guarantee call/apply 
 while a DOMFunction could require a try catch or a different behavior 
 for IE

 switch(true){
 case $.isFunction(fn): return fn.call(what, ever);
 case $.isDOMFunction(fn): what.push.call(what, toArray(fn(ever))); 
 return what;
 default: throw new Error(what tf?);
 }

 ... or maybe not?
 Regards



 On Sun, Jul 26, 2009 at 4:09 PM, Andrea Giammarchi 
 andrea.giammar...@gmail.com mailto:andrea.giammar...@gmail.com wrote:

 I usually encapsulate toString from Object.prototype and if
 somebody breaks the rule it means we cannot trust anything
 included typeof. So, in few words, nobody has intersts into break
 this rule, imho.

 On Jul 26, 2009 8:07 AM, DBJDBJ dbj...@gmail.com
 mailto:dbj...@gmail.com wrote:


 Also, IMHO this yields high level of encapsulation of an important
 mechanism.
 Which is a good thing.
 And it is a fraction of a micro second slower then

 Object.prototype.toString.call(x) === [object Object]

 but it is more compact ...

 In any case we are entering the subjective judgement phase, so I
 think
 we should stop here and leave it to jQuery team to use this or not...

 --DBJ On Jul 26, 12:09 am, Andrea Giammarchi
 andrea.giammar...@gmail.com
 mailto:andrea.giammar...@gmail.com wrote:

  I miss the point about regexp usage ... please tell me the
 difference (in a  real scenario) betwe...

  On Sat, Jul 25, 2009 at 1:38 PM, DBJDBJ dbj...@gmail.com
 mailto:dbj...@gmail.com wrote:This indeed woks :  functi...



 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---



[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-27 Thread Andrea Giammarchi
Yes Ariel, I was talking about user defined stuff and obviously typeof
unknown breaks the rule as well but this is not the case, is it?

If toString.call(obj) is not reliable cause it could return [object Object]
DBJ mess is not reliable as well because passed variable could not produce
what he is expecting, starting from document.getElementById which is object
and not function in IE, got the point?

At least you told me why there is a call rather than an instanceof but what
about this for IE DOM functions?

return !!obj  typeof obj.toString === undefined 
/^\s*\bfunction\b/.test(obj);

it works fine to me in every IE (other browsers will be filtered by first
feature test)

Regards

On Mon, Jul 27, 2009 at 5:29 PM, Daniel Friesen
nadir.seen.f...@gmail.comwrote:


 typeof fn === 'function'; // Some things like
 document.createElement('object'); return wonky results
 fn instanceof Function; // Breaks across iFrames
 toString.call(fn) === [object Function]; // Works the same across
 iFrames and returns more reliable results

 ~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]

 Andrea Giammarchi wrote:
  About isFunction
 
  I lost the point where toString.call(obj) === [object Function] was
  introduced instead of obj instanceof function
 
  I understand differences in IE so I wonder if two distinct callbacks
  could solve the odyssey:
 
  isFunction: function( obj ) {
  return obj instanceof Function;
  },
 
  isDOMFunction: toString.call(window.alert) === [object Function] ?
  function( obj ) {
  return toString.call(obj) === [object Function];
  }:
  // IE only and only until standard native function manifest
  function( obj ){
  return !!obj  typeof obj.toString === undefined 
  /^\s*\bfunction\b/.test(obj);
  }
  ,
 
  In this way we could consider that in every browser, and when
  call/apply are supported, isFunction(fn) will guarantee call/apply
  while a DOMFunction could require a try catch or a different behavior
  for IE
 
  switch(true){
  case $.isFunction(fn): return fn.call(what, ever);
  case $.isDOMFunction(fn): what.push.call(what, toArray(fn(ever)));
  return what;
  default: throw new Error(what tf?);
  }
 
  ... or maybe not?
  Regards
 
 
 
  On Sun, Jul 26, 2009 at 4:09 PM, Andrea Giammarchi
  andrea.giammar...@gmail.com mailto:andrea.giammar...@gmail.com
 wrote:
 
  I usually encapsulate toString from Object.prototype and if
  somebody breaks the rule it means we cannot trust anything
  included typeof. So, in few words, nobody has intersts into break
  this rule, imho.
 
  On Jul 26, 2009 8:07 AM, DBJDBJ dbj...@gmail.com
  mailto:dbj...@gmail.com wrote:
 
 
  Also, IMHO this yields high level of encapsulation of an important
  mechanism.
  Which is a good thing.
  And it is a fraction of a micro second slower then
 
  Object.prototype.toString.call(x) === [object Object]
 
  but it is more compact ...
 
  In any case we are entering the subjective judgement phase, so I
  think
  we should stop here and leave it to jQuery team to use this or
 not...
 
  --DBJ On Jul 26, 12:09 am, Andrea Giammarchi
  andrea.giammar...@gmail.com
  mailto:andrea.giammar...@gmail.com wrote:
 
   I miss the point about regexp usage ... please tell me the
  difference (in a  real scenario) betwe...
 
   On Sat, Jul 25, 2009 at 1:38 PM, DBJDBJ dbj...@gmail.com
  mailto:dbj...@gmail.com wrote:This indeed woks :
  functi...
 
 
 
  

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---



[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-27 Thread Andrea Giammarchi
Yes Daniel ... ( sorry I had another ticket open and I read Ariel ... )

On Mon, Jul 27, 2009 at 5:43 PM, Andrea Giammarchi 
andrea.giammar...@gmail.com wrote:

 Yes Ariel, I was talking about user defined stuff and obviously typeof
 unknown breaks the rule as well but this is not the case, is it?

 If toString.call(obj) is not reliable cause it could return [object Object]
 DBJ mess is not reliable as well because passed variable could not produce
 what he is expecting, starting from document.getElementById which is object
 and not function in IE, got the point?

 At least you told me why there is a call rather than an instanceof but what
 about this for IE DOM functions?

 return !!obj  typeof obj.toString === undefined 
 /^\s*\bfunction\b/.test(obj);

 it works fine to me in every IE (other browsers will be filtered by first
 feature test)

 Regards

 On Mon, Jul 27, 2009 at 5:29 PM, Daniel Friesen nadir.seen.f...@gmail.com
  wrote:


 typeof fn === 'function'; // Some things like
 document.createElement('object'); return wonky results
 fn instanceof Function; // Breaks across iFrames
 toString.call(fn) === [object Function]; // Works the same across
 iFrames and returns more reliable results

 ~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]

 Andrea Giammarchi wrote:
  About isFunction
 
  I lost the point where toString.call(obj) === [object Function] was
  introduced instead of obj instanceof function
 
  I understand differences in IE so I wonder if two distinct callbacks
  could solve the odyssey:
 
  isFunction: function( obj ) {
  return obj instanceof Function;
  },
 
  isDOMFunction: toString.call(window.alert) === [object Function] ?
  function( obj ) {
  return toString.call(obj) === [object Function];
  }:
  // IE only and only until standard native function manifest
  function( obj ){
  return !!obj  typeof obj.toString === undefined 
  /^\s*\bfunction\b/.test(obj);
  }
  ,
 
  In this way we could consider that in every browser, and when
  call/apply are supported, isFunction(fn) will guarantee call/apply
  while a DOMFunction could require a try catch or a different behavior
  for IE
 
  switch(true){
  case $.isFunction(fn): return fn.call(what, ever);
  case $.isDOMFunction(fn): what.push.call(what, toArray(fn(ever)));
  return what;
  default: throw new Error(what tf?);
  }
 
  ... or maybe not?
  Regards
 
 
 
  On Sun, Jul 26, 2009 at 4:09 PM, Andrea Giammarchi
  andrea.giammar...@gmail.com mailto:andrea.giammar...@gmail.com
 wrote:
 
  I usually encapsulate toString from Object.prototype and if
  somebody breaks the rule it means we cannot trust anything
  included typeof. So, in few words, nobody has intersts into break
  this rule, imho.
 
  On Jul 26, 2009 8:07 AM, DBJDBJ dbj...@gmail.com
  mailto:dbj...@gmail.com wrote:
 
 
  Also, IMHO this yields high level of encapsulation of an important
  mechanism.
  Which is a good thing.
  And it is a fraction of a micro second slower then
 
  Object.prototype.toString.call(x) === [object Object]
 
  but it is more compact ...
 
  In any case we are entering the subjective judgement phase, so I
  think
  we should stop here and leave it to jQuery team to use this or
 not...
 
  --DBJ On Jul 26, 12:09 am, Andrea Giammarchi
  andrea.giammar...@gmail.com
  mailto:andrea.giammar...@gmail.com wrote:
 
   I miss the point about regexp usage ... please tell me the
  difference (in a  real scenario) betwe...
 
   On Sat, Jul 25, 2009 at 1:38 PM, DBJDBJ dbj...@gmail.com
  mailto:dbj...@gmail.com wrote:This indeed woks :
  functi...
 
 
 
  

 



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---



[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-26 Thread Andrea Giammarchi
I usually encapsulate toString from Object.prototype and if somebody breaks
the rule it means we cannot trust anything included typeof. So, in few
words, nobody has intersts into break this rule, imho.

On Jul 26, 2009 8:07 AM, DBJDBJ dbj...@gmail.com wrote:


Also, IMHO this yields high level of encapsulation of an important
mechanism.
Which is a good thing.
And it is a fraction of a micro second slower then

Object.prototype.toString.call(x) === [object Object]
but it is more compact ...

In any case we are entering the subjective judgement phase, so I think
we should stop here and leave it to jQuery team to use this or not...

--DBJ On Jul 26, 12:09 am, Andrea Giammarchi andrea.giammar...@gmail.com
wrote:

 I miss the point about regexp usage ... please tell me the difference (in
a  real scenario) betwe...

 On Sat, Jul 25, 2009 at 1:38 PM, DBJDBJ dbj...@gmail.com wrote:   
This indeed woks :  functi...

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---



[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-25 Thread Andrea Giammarchi
I miss the point about regexp usage ... please tell me the difference (in a
real scenario) between these two checks:

Object.prototype.toString.call(x) === Object.prototype.toString.call({})

and

Object.prototype.toString.call(x).match(/\w+/g)[1] ===
Object.prototype.toString.call({}).match(/\w+/g)[1]

finally please tell me the difference with this:

Object.prototype.toString.call(x) === [object Object]

I am usually against redundant, slow, or superflous code ... maybe I am
wrong here, am I?


On Sat, Jul 25, 2009 at 1:38 PM, DBJDBJ dbj...@gmail.com wrote:



 This indeed woks :  function isObj(o){ return
 Object.prototype.toString.call(o) === '[object Object]' }

 But I do not like it ;o) It does not seem very exact somehow ... I
 mean using a string literal, and all that...
 I would suggest this very simple and robust little set of functions :

 // and now much simpler implementation
 function isWhat(o){ return Object.prototype.toString.call(o).match(/\w
 +/g)[1]; }

 function isObject(x) { return isWhat(x) === isWhat({}); }
 function isArray(x)  { return isWhat(x) === isWhat([]); }
 function isFunction(x) { return isWhat(x) === isWhat(Function()); }
 function isString(x) { return isWhat(x) === isWhat(); }
 function isNumber(x) { return isWhat(x) === isWhat(1); }

 No obfuscations here, and no awesome code. This seems very simple
 and robust solution to me.

 --DBJ


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---



[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-25 Thread DBJDBJ


var dbj = {} ;
 dbj.isWhat = function(o) { return Object.prototype.toString.call
(o).match(/\w+/g)[1]; }

// optimization
dbj.TYPENAMES = { 'obj' : dbj.isWhat({}), 'arr' : dbj.isWhat([]),
 'fun' : dbj.isWhat(Function()), 'str' : dbj.isWhat
(),
 'num'   : dbj.isWhat(1) } ;

 dbj.isObject = function(x) { return dbj.isWhat(x) ===
dbj.TYPENAMES.obj; }
 dbj.isArray = function(x) { return dbj.isWhat(x) ===
dbj.TYPENAMES.arr; }
 dbj.isFunction = function(x) { return dbj.isWhat(x)
=== dbj.TYPENAMES.fun; }
 dbj.isString = function(x) { return dbj.isWhat(x) ===
dbj.TYPENAMES.str; }
 dbj.isNumber = function(x) { return dbj.isWhat(x) ===
dbj.TYPENAMES.num; }

Above will work equaly well without regexp inside isWhat(), but , I
like to have a typename as 'Object' rather than '[object Object]'. You
never know which browser/OS combination will break the rules and
return some slightly different format from Object.prototype.toString
()...

All of this is just (re)packaging of the usage of
Object.prototype.toString.call(x), mechanism.
Without string literals, and without using 'typeof'.
And, as I said this implementation seems simple, rounded and portable
to me.  ( allow me to mention non-browser environments where this also
will work) .

--DBJ


On Jul 26, 12:09 am, Andrea Giammarchi andrea.giammar...@gmail.com
wrote:
 I miss the point about regexp usage ... please tell me the difference (in a
 real scenario) between these two checks:

 Object.prototype.toString.call(x) === Object.prototype.toString.call({})

 and

 Object.prototype.toString.call(x).match(/\w+/g)[1] ===
 Object.prototype.toString.call({}).match(/\w+/g)[1]

 finally please tell me the difference with this:

 Object.prototype.toString.call(x) === [object Object]

 I am usually against redundant, slow, or superflous code ... maybe I am
 wrong here, am I?

 On Sat, Jul 25, 2009 at 1:38 PM, DBJDBJ dbj...@gmail.com wrote:

  This indeed woks :  function isObj(o){ return
  Object.prototype.toString.call(o) === '[object Object]' }

  But I do not like it ;o) It does not seem very exact somehow ... I
  mean using a string literal, and all that...
  I would suggest this very simple and robust little set of functions :

  // and now much simpler implementation
  function isWhat(o){ return Object.prototype.toString.call(o).match(/\w
  +/g)[1]; }

  function isObject(x) { return isWhat(x) === isWhat({}); }
  function isArray(x)  { return isWhat(x) === isWhat([]); }
  function isFunction(x) { return isWhat(x) === isWhat(Function()); }
  function isString(x) { return isWhat(x) === isWhat(); }
  function isNumber(x) { return isWhat(x) === isWhat(1); }

  No obfuscations here, and no awesome code. This seems very simple
  and robust solution to me.

  --DBJ
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---



[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-24 Thread DBJDBJ

To prove the point (or not) one can do this :

isObject : function ( obj ) {
  if ( (this.constructor + ).match(/Object/))  alert
( this.constructor ) ;
  return this.constructor.call(obj) === Object;
   }

if this is Object the result will be false. Allways.

--DBJ
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---



[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-24 Thread Mark Gibson

$.isObject({}) returns false!

I see that $.isObject is used in $.extends, to test whether an empty
object should be created:

if ( src ) {
clone = src;
} else if ( jQuery.isArray(copy) ) {
clone = [];
} else if ( jQuery.isObject(copy) ) {
clone = {};
} else {
clone = copy;
}

So, in this situation we are not interested in other native objects
(ie. Date, RegExp, etc.) which will be treated as immutable values, so
why not just use:

isObject: function( obj ) {
return toString.call(obj) === [object Object];
}

-- Mark

2009/7/23 John Resig jere...@gmail.com:
 I'll rope Yehuda in to see if he can explain it.

 --John


 On Thu, Jul 23, 2009 at 4:18 AM, Balazs Endresz balazs.endr...@gmail.com
 wrote:

 It has been marked as invalid and suggested to bring it up here:
 http://dev.jquery.com/ticket/4946



 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---



[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-24 Thread Nick Fitzsimons

2009/7/24 Samer Ziadeh samerzia...@gmail.com:
 isn't everything an object?

No:

typeof 2; // returns number
typeof new Number(2); // returns object
typeof ; // returns string
typeof new String(); // returns object

Primitive types such as string and number will be automatically
converted to an object of the appropriate type if necessary (e.g.
2.valueOf()) but they are not objects as such. See ECMAScript 262
section 4.3, and section 9 on Type Conversion.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---



[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-24 Thread DBJDBJ


if ( Function !== typeof String.prototype.strim )
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,
''); }

function isWhat ( x ) {
  return (+x.constructor).split(()[0].split(function)[1].trim
() ;
 // or your clever RegEx here ...
}

function isObject ( x ) {
  return isWhat(x) === Object ;
}

function isArray ( x ) {
  return isWhat(x) === Array ;
}

// and so on ... for other types

IMHO this might be one of the alternatives, also very strict and
robust ...

--DBJ

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---



[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-24 Thread James Padolsey

Checking the constructor is a bad idea; if you try checking the
constructor of an object within an iframe it won't have the same
constructor as an object outside of the iframe. I think this'll do
what's required:

function isObj(o){ return Object.prototype.toString.call(o) ===
'[object Object]' }

from: 
http://thinkweb2.com/projects/prototype/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/

On 24 July, 15:00, DBJDBJ dbj...@gmail.com wrote:

 function isWhat ( x ) {
   return (+x.constructor).split(()[0].split(function)[1].trim
 () ;
  // or your clever RegEx here ...

 }
 --DBJ
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---



[jquery-dev] Re: Ticket #4946, jQuery.isObject

2009-07-23 Thread Samer Ziadeh
isn't everything an object?

On Thu, Jul 23, 2009 at 07:52, John Resig jere...@gmail.com wrote:

 I'll rope Yehuda in to see if he can explain it.

 --John



 On Thu, Jul 23, 2009 at 4:18 AM, Balazs Endresz 
 balazs.endr...@gmail.comwrote:


 It has been marked as invalid and suggested to bring it up here:
 http://dev.jquery.com/ticket/4946



 



-- 
Samer Ziadeh
www.samerziadeh.com


Let It Be

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
jQuery Development group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~--~~~~--~~--~--~---