fordth / jinqJs

jinqJs provides a simple way to perform SQL like queries on javaScript arrays, collections and web services using LINQ expressions.
Other
93 stars 29 forks source link

Problem function isObject, ... #10

Closed zaideygrek closed 7 years ago

zaideygrek commented 8 years ago

Of course, thanks for your job !

When we want to check an object, it seems preferable to use "typeof".

isObject  = function (obj) {
  return (obj !== null && obj.constructor === Object);
}

to

isObject  = function (obj) {
  return (obj !== null && typeof obj === 'object');
}
fordth commented 8 years ago

zaideygrek, thanks for the recommendation. I do remember a while back considering which way to use and found that they return different results when passing in an array. See here: http://jsbin.com/fadifiwefu/edit?js,console

If you think there could be a performance improvement with one over the other I can look into adding the change and rerunning the unit tests to see if anything breaks. Thanks for the recommendation, let me know your thoughts.

-Tom

zaideygrek commented 8 years ago

Hello tom thanks for reply,

I have the problem when I get back the object $resource from angular. obj.constructor is no equal to object. I would recommend you code: http://jsbin.com/saditapato/edit?js,console

Alex

fordth commented 8 years ago

Thanks zaideygrek, I will take a look this weekend. Sorry for the delayed response.

fordth commented 8 years ago

zaideygrek,

I made your recommended changes and to my surprise I had a lot of unit tests fail. The problem is the javascript function Array.isArray() returns false on the arguments array. See here for my demo http://jsbin.com/cabajukida/edit?js,console